TypeScript学习类型推断let str = 'abc'str只能是字符串类型,不能再被赋予别的数据类型类型注解let str: string = 'abc'类型断言let numArr = [1,2,3]
const result = numArr.find(item => item > 2) as number
result * 5通过as来断定类型基础类型和联合类型let v4: string | null = null一个变量可能会被赋予多种类型,用| 间隔赋值限定:let v5: 1 | 2 | 3 = 2数组限定类型let arr: number[] = [1,2,3]
let arr1: Array<string> = ['a','b','c']元组let t1: [number,string,number?] = [1,'a']?代表可选枚举:enum MyEnum {
A,
B,
C
}
//调
Vergessen