当前位置:网站首页>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 >?
边栏推荐
- Hyperledger caliper is built on fabric for performance test
- Qt的QTextToSpeech类实现语音播报功能
- focal loss
- OneNote code highlighting
- 内置模块10.18
- Summenudemo (submenu)
- [Redis] Redis几种部署方式
- 函数优先顺序
- JVM概述和内存管理(未完待续)
- Hacker introductory tutorial (very detailed) from zero basic introduction to proficiency, it is enough to read this one.
猜你喜欢
随机推荐
Function summary
[basic knowledge of deep learning - 42] detailed explanation of logistic regression
Togglebutton (button switch)
[basic knowledge of deep learning - 41] quick start learning materials for deep learning
C243:考试排名
10.31静态路由的扩展配置
Combinatorics -- permutation and combination
Introduction to reinforcement learning
[Redis] Redis穿透、雪崩和击穿
View pagoda PHP extension directory
顶级“黑客”能厉害到什么地步?无信号也能上网,专家:高端操作!
Adults have only one main job, but they have to pay a price. I was persuaded to step back by personnel, and I cried all night
What's new in helix QAC 2022.2, the ace code static testing tool (2)
NAT 11.16
第2章 入门
focal loss
Detailed interpretation of IEC104 protocol (I) protocol structure
Cesium常用坐标系详细介绍
Sword finger offer 25. merge two sorted linked lists
pytorch lstm+attention







