I'm learning Angular and Typescript, I have been doing some small coding but I reached the roof, I can't find a solution for my problem anywhere.
I was able to successfully declare simple types and array of simple types but I'm unable to create an array of objects.
someArray = new Array<ObjectType>();
class ObjectType {
constructor( name: string, age: number) {
}
}
and then I try to add element to an array
someArray.push(new ObjectType('John',5) );
and get an error:
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.
How can this be a duplicate? Thank you in advance.
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
someArray = new Array<ObjectType>();
someArray.push(new ObjectType('John',5) );
}
class ObjectType{
constructor( name: string, age: number){
}
}
someArraytwiceapp.component.tsas that is where the error seems to originate from.