我聲明類型:如何使用自定義類型遍歷數組?
export interface Type{
id: number;
name: string;
}
現在我想遍歷這個類型的數組:
for(var t of types) // types = Type[]
{
console.log(t.id);
}
我得到錯誤:
D:/Google/services/test.service.ts (33,20): Property 'id' does not exist on type 'Type'.
我不查看該代碼中的任何錯誤。你確定這兩個片段的輸入是相同的界面嗎? – lilezek
固定。我重新啓動服務,一切正常。 –
刪除問題然後 –