interfaceLabelType{
id: number;// label id
txt: string;// label值}const func1 =(obj: LabelType){// ...}// 或者使用解构的写法const func2 =({ id, txt }: LabelType){// ...}func({
readonly id:1,// 'readonly' 表示只读属性
txt?:'this is a string.'// '?' 表示为可选属性})
类型断言
let str: any ="this is a string."// 第一种使用尖括号的用法let asset1: number =(<string>str).length
// 另一种使用 as 语法let asset2: number =(str as string).length
泛型
// 声明泛型函数function identify<T>(arg:T):T{// ...}// 使用泛型约束const str1 = identify<string>("this is a string.");// 另一种简洁写法const str2 =identify("this is other string.")