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.")