1,布尔
let isDone:boolean = false;
2, 数字, 所有数字都是浮点数
let n:number = 1;
3,字符串
let name:string = "mily", sex:string = '女';
4.数组
let arr1:number[] = [1, 2, 3]
let arr2:Array<number> = [1, 2, 3]
5,元祖, 已知元素数量和类型,元素类型不必相同
let x = [number, string];
x = [a, 1]
6,枚举
enum Color {Red, Green, Blue};
let c:Color = Color.red;
7,unknown 不指定类型
let notsure:unknown = 'hellow';
let notsure2:unknown = 2;
8, void 通常指没有返回值的函数
function test():void {console.log('.....')
}
9, null和undefined
let n:null = null;
let u:undefined = undefined;
10, 联合类型,表示取值可以为多种类型中的一种;
let ab: number|string;
ab = 2;
ab = 'str';