Im getting this compilation error in my Angular 2 app:
TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'.
The piece of code causing it is:
getApplicationCount(state:string) {
return this.applicationsByState[state] ? this.applicationsByState[state].length : 0;
}
This however doesn't cause this error:
getApplicationCount(state:string) {
return this.applicationsByState[<any>state] ? this.applicationsByState[<any>state].length : 0;
}
This doesn't make any sense to me. I would like to solve it when defining the attributes the first time. At the moment I'm writing:
private applicationsByState: Array<any> = [];
But someone mentioned that the problem is trying to use a string type as index in an array and that I should use a map. But I'm not sure how to do that.