摘要: 泛型变量 function identity<T>(arg: T): T { return arg } function loggingIdentity<T>(arg: T[]): T[] { console.log(arg.length) return arg } 泛型函数 loggingIden 阅读全文
posted @ 2021-11-10 13:18 webLion200 阅读(41) 评论(0) 推荐(0) 编辑
摘要: as is as 是类型断言 let someValue: any = 'this is a string' let strLength: number = (someValue as string).length is 用于类型保护 function isString(test: any): te 阅读全文
posted @ 2021-11-10 13:18 webLion200 阅读(14) 评论(0) 推荐(0) 编辑
摘要: 函数类型 书写完整函数类型 函数类型包含两部分:参数类型和返回值类型。 let myAdd: (x: number, y: number) => number = function(x: number, y: number) { return x + y } 推断类型 在赋值语句的一边指定了类型但是 阅读全文
posted @ 2021-11-10 13:17 webLion200 阅读(18) 评论(0) 推荐(0) 编辑
摘要: 属性检查 类接口带有几个确定的属性,同时还会带有其他不确定的属性时,可如下定义: interface SquareConfig { color?: string width?: number [propName: string]: any } 使用类型断言(as)跳过检查 let mySquare 阅读全文
posted @ 2021-11-10 13:17 webLion200 阅读(27) 评论(0) 推荐(0) 编辑
摘要: 继承 class Animal { move(distance: number = 0) { console.log(`Animal moved ${distance}m.`) } } class Dog extends Animal { bark() { console.log('Woof! Wo 阅读全文
posted @ 2021-11-10 13:16 webLion200 阅读(39) 评论(0) 推荐(0) 编辑
摘要: 布尔值 let isDone: boolean = false 数字 let decLiteral: number = 20 let hexLiteral: number = 0x14 let binaryLiteral: number = 0b10100 let octalLiteral: num 阅读全文
posted @ 2021-11-10 13:15 webLion200 阅读(36) 评论(0) 推荐(0) 编辑