我正在学习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 .
这怎么可能是重复的? 谢谢你的建议