我正在學習Angular和typeScript,我寫了一些小代碼,但是我到達了屋頂,我找不到解決問題的方法。
我能夠成功聲明簡單類型和簡單類型數組,但是我無法創建一個對象數組。someArray = new Array();class ObjectType {
constructor( name: string, age: number) {
}
}
然後我嘗試向數組中添加元素someArray.push(new ObjectType('John',5) );
並得到一個錯誤:
Duplicate identifier'someArray'.ts(2300 )
Subsequent property declarations must have the same type . Property'someArray'must be of type'ObjectType []',but here has type'any'.ts(2717 )
app.component.ts(10,3):'someArray'was also declared here .
這怎麼可能是重複的? 謝謝你的建議