关于文档中的断言
来源:2-2 配置 eslint、 prettier 和 commitlint 规范工程

慕神2393367
2021-08-09
interface Shape {
color: string;
}
interface Square extends Shape {
sideLength: number;
}
// let square = {} as Square; // 官网中使用断言
let square:Square = {color: undefined, sideLength: undefined} // 我改成这样也正常的 所以不懂为啥要断言
square.color = "blue";
square.sideLength = 10;```
我把官方文档中的断言写法改成赋值成undefined没有报错,所以我不懂为啥要用断言
写回答
1回答
-
Nolan
2021-08-10
可以看这里:https://imfaber.me/typescript-type-declarations-vs-type-assertions/
00
相似问题