2017-05-05 125 views
0

創建的屬性的任何量的一個接口I具有以下哈希表:與打字稿

{ 
    1: [1, 2, 3, 4], 
    2: [1, 2, 3, 4], 
    ... 
} 

對象密鑰是類的數目和陣列具有學生的數量。

如何定義鍵的接口?

// pseudo code 
interface ClassStudentRelationshipInterface { 
    {any amount of keys should be a number}: number[]; 
} 

謝謝。

回答

3

您可以用number類型的關鍵接口指定index signature

interface ClassStudentRelationshipInterface { 
    [key: number]: number[]; 
}