TypeSript【官网】
【READBOOK】https://www.bookstack.cn/read/wangdoc-typescript-tutorial/docs-d.ts.md
ts是js的一个超集,解决js类型支持
js: 动态类型
ts:静态类型 代码执行的顺序是先编译在执行 发现错误更早
1.为什么要添加类型支持?
2.优势有什么?
3.全局安装
npm i -g typescript
tsc -v
4.简化运行ts的步骤
5.typescript常用类型
类型检查机制
5.1 类型注解
5.2 常用基础类型
5.3 原始类型
6.数组类型
7.类型别名 type关键字
1 2 3 4 5 6
| type CustomArray = (number|string)[] let arr1:CustomArray = [1,2,'a',3] let arr2:CustomArray = [1,4,'a',3] console.log(arr1); console.log(arr2);
|
8.函数类型
9.可选参数
10.对象类型
对象的类型其实就是在描述对象的结构
11.对象中的可选属性
12.接口【复用】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| interface IPerson{ name:string age:number sayhi():void }
let person_3:IPerson ={ name:'JACL', age:11, sayhi(){} }
let person_4:IPerson ={ name:'JAC33L', age:33, sayhi(){} } console.log(person_3);
console.log(person_4);
|
13.接口和类型别名
1 2 3 4 5
| type num = number | string let a:num = 1 let b:num = 'asf' console.log(a); console.log(b);
|
14.接口继承复用
15.元组
16.类型推论
17.类型断言
18.字面量类型
19.枚举类型
20.字符串枚举
21.枚举特点
22.any类型
23.ypeof
24.TS高级类型
24.1 class
25.类的实例方法
26.类的继承
27.类成员可见性
28.类型兼容性
29.对象兼容性
30.接口兼容性
31.函数兼容性
32.类型兼容性
33.交叉类型
34.交叉类型(&)和接口继承(extends)的区别
35.泛型
36.简化调用泛型函数
37.泛型循环
38.添加约束
39.泛型的类型变量
40.泛型接口
41.JS中的数组就是TS中的一个泛型接口
42.class配合泛型来使用
43.泛型工具类型
43.1 partial
43.2 readonly
43.3 pick
43.4 record
44.索引签名类型
45.映射类型
45.1 基于旧类型进行创建
45.2 基于对象创建
45.3 引查询类型
45.4 同时查询多个索引的类型
46.d.ts 类型声明文件
47.TS中的两种文件类型
48.类型声明文件的使用说明
49.使用已有的类型声明文件
49.1 内置api
49.2 第三方库的类型声明
49.3 definitelyTyped
49.4 创建自己的声明文件
49.5 项目内共享类型
49.6 为已有js文件提供类型声明
50.【webpack】搭建一个基本的webpack4.x项目
51.React支持TS