
typescript
limingzhangabc
弱者抱怨人生,强者迎难而上
展开
-
TypeScript - interface(接口)
TypeScript – interface 概念: TypeScript接口定义对象的类型(我的理解:定义对象属性的类型和提炼类中的公共方法) 类别: 接口的可选属性: 接口中的属性不全是必须的, 带有可选属性的接口和普通的接口差不多, 只是在可选属性后添加 ’ ?’ // 可选属性的接口 interface SquareConfig { color? : string; wi原创 2017-10-10 16:47:45 · 1357 阅读 · 0 评论 -
TypeScript - 类
类的继承: 面向对象的模式 super: 关键字 class Animal { name: string; constructor(theName: string) { this.name = theName; } move(distanceInMeters: number = 0) { console.log(`${this.name} moved ${dist原创 2017-10-10 18:14:55 · 364 阅读 · 0 评论 -
TypeScript - 泛型
概念: 支持当前的数据类型,还支持未来的数据类型 // 泛型 <T> 类型变量 function identity<T>(arg: T): T { return arg; }@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css']原创 2017-10-11 15:37:00 · 791 阅读 · 0 评论 -
TypeScript-基础类型
布尔值 Boolean 数字 number 字符串 string 数组 [] 元组 枚举 任意值 空值 null 和undefined never 数组, ts数组可以想JavaScript那样操作数组 定义数组:// 方式一: 元素类型后接上[] let list: number[] = [1,2,3]; // 方式二: 数组泛型 let list: Array<numbe原创 2017-10-12 15:09:18 · 494 阅读 · 0 评论 -
TypeScript - 1.8类型推论
上下文类型: window.onmousedown = function(mouseEvent) { console.log(mouseEvent.button); //error } window.onmousedown = function(mouseEvent: any) { console.log(mouseEvent.button); }原创 2017-10-12 15:45:19 · 364 阅读 · 0 评论