陣列的型別
「型別 + 方括號」表示法
let fibonacci: number[] = [1, 1, 2, 3, 5];let fibonacci: number[] = [1, '1', 2, 3, 5];
// Type 'string' is not assignable to type 'number'.let fibonacci: number[] = [1, 1, 2, 3, 5];
fibonacci.push('8');
// Argument of type '"8"' is not assignable to parameter of type 'number'.陣列泛型
let fibonacci: Array<number> = [1, 1, 2, 3, 5];用介面表示陣列
類別陣列
any 在陣列中的應用
參考
Last updated