当前位置:网站首页>TS2532: Object is possibly ‘undefined‘
TS2532: Object is possibly ‘undefined‘
2022-07-27 17:28:00 【qwe122343】
TypeScript 的规矩很多,用起来很是严谨。
定义了一个函数的接口,参数 x, y, z ( z可选 ) 均为number,返回值为 number 类型
interface AddFunction22 {
(x: number, y: number, z?: number): number;
}
const add3333: AddFunction22 = (x, y, z) => x + y + z;
console.log(add3333(23, 546, 67));
然后就报错:
解决方案:给参数 z 增加类型断言
将 const add3333: AddFunction22 = (x, y, z) => x + y + z;
改成:const add3333: AddFunction22 = (x, y, z) => x + y + (z as number);
这里类型段言推荐用 z as number 的写法,用 <number>z 会提示 Parsing error: Unexpected token. Did you mean {'>'} or >?
边栏推荐
- 10.31 extended configuration of static route
- 深度主动学习综述2020
- No experts! Growth secrets for junior and intermediate programmers and "quasi programmers" who are still practicing in Universities
- Hyperledger caliper is built on fabric for performance test
- Turn Hyper-V on and off
- OneNote code highlighting
- mysql函数汇总之系统信息函数
- View pagoda PHP extension directory
- Fabric上搭建Hyperledger caliper进行性能测试
- NAT 11.16
猜你喜欢

Common errors reported by pytorch
![[basic knowledge of deep learning - 42] detailed explanation of logistic regression](/img/74/d7d1562ada4671864961721b9a1baf.png)
[basic knowledge of deep learning - 42] detailed explanation of logistic regression

聊聊 Redis 是如何进行请求处理

Marqueetextview (running lantern)

Version announcement | Apache Doris 1.1 release version officially released!

Qt的QTextToSpeech类实现语音播报功能
![[basic knowledge of deep learning - 37] solve the imbalance between positive and negative samples](/img/71/4052607951eb52862a6fd36366f216.png)
[basic knowledge of deep learning - 37] solve the imbalance between positive and negative samples

UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte

访问控制

Systemservice (system service)
随机推荐
GridView (implement table display icon)
Combinatorics -- permutation and combination
C191:密码编译
11.5.OSPF
Influxdb series (IV) TSM engine (storage principle)
Normalization and standardization
Install Talib Library under Anaconda
Hyperledger caliper is built on fabric for performance test
Chapter 2 Introduction
剑指 Offer 25. 合并两个排序的链表
Object常用方法学习【clone和equals】
Introduction to reinforcement learning
ACL11.12
mysql函数汇总之系统信息函数
由单片机XTALIN引脚和XTALOUT引脚导出的对晶体震荡电路的深入理解
An unknown fastcgi error occurred in IIS: 0x80070005
SQlife(数据库)
聊聊 Redis 是如何进行请求处理
真实案例,大学生接单被骗,希望大家不要被骗了【惨痛教训】
DCM11- 根据标识符写入数据服务 ($2E)的功能和配置【基于DaVinci Configurator Classic】