1.boolen 布尔类型
let boolen1: boolen = false;
2.number 数字类型
let num1: number = 0b110;//二进制
let num2: number = 10;//十进制
3.string 字符串类型
let str1: string = `姓名:${name}`
4.array 数组类型
let arr1: Array<number> = [1,2,3];
let arr2:number[] = [1,2,3];
5.tuple 元祖类型 - 已知元素数量和和类型的数组
let x:[string,number];
x = ['zh',4];//运行正常
x = [1,2];//报错
6.enum 枚举类型
export enum ActionTypes {
Increment = '[Counter Component] Increment',
Decrement = '[Counter Component] Decrement',
Reset = '[Counter Component] Reset',
}
7.any 任意类型
8.null 和 undefined
let x:number | null | undefined
9.void 类型
function hello(): void {
alert("Hello Angular");
}
10.never 类型
11.对象类型:使用interface定义
interface ObjectData {
imgSrc: string;
text: string;
}
let data :ObjectData = {
imgSrc:"https://source.unsplash.com/random",
text:"this is a picture"
};
let arrayData: Array<ObjectData> = Object[];
//二维数组的表示方法: Array<Array<Object>> = Object[][]