TypeScript学习笔记 对象类型接口&函数类型接口
对象类型接口
- 接口可以用来约束对象,函数以及类的结构和类型。
定义接口
- 即使传入多余的字段也可以通过类型检查。
|
绕过类型检查
- 类型断言
|
|
- 字符串索引签名
- 用任意的字符串索引
list
可以得到任意的结果。 list
就可以支持多个属性。
- 用任意的字符串索引
|
可选属性
- 属性后加上
?
,表示可选属性。
|
只读属性
- 属性前加上
readonly
,表示只读属性。
|
可索引接口
- 数字索引接口,相当于字符串类型的数组。
|
- 字符传索引接口。
|
- 混合索引接口。注意返回的类型。
|
函数类型接口
|