
ts
V_AYA_V
且就洞庭赊月色,将船买酒白云边
展开
-
ts学习笔记-function
函数函数类型建议给每个参数添加类型之后再为函数本身添加返回值类型。 TypeScript 能够根据返回语句自动推断出返回值类型,因此通常省略。function add(x: number, y: number) { return x + y;}完整的函数类型包含参数定义和类型定义。不在乎参数的名字,类型相同即认为是有效的函数类型。当无返回值时需要定义成 void 不能省略。赋值语句一边指定了类型,另一边没有指定类型编译器会自动识别类型。// 完整的函数类型let myAdd:原创 2021-06-03 14:57:46 · 727 阅读 · 0 评论 -
ts学习笔记-interface
接口可选属性interface SquareConfig { color?: string; width?: number;}function createSquare(config: SquareConfig): { color: string, area: number } { // ...}额外的属性检查:跳过 interface 属性检测的方式类型断言添加字符串索引签名将对象赋值给另外一个变量// 类型断言let mySquare = createSquar原创 2021-05-24 15:31:21 · 615 阅读 · 0 评论 -
ts学习笔记-class
TS学习-类类的继承当派生类中有 constructor 构造函数的时候,一定要调用 super()->执行基类的构造函数。在派生类中使用 this 之前一定要使用 super()class Animal { name: string; constructor(theName: string) { this.name = theName; } move(name: string) { console.log(`${name}说:我能移动`); }}class Dog e原创 2021-05-24 15:28:24 · 160 阅读 · 0 评论