I have the following code in TypeScript:
export class Config
{
private options = new Map<string, string>();
constructor() {
}
public getOption(name: string): string {
return this.options[name]; // <-- This line causes the error.
}
}
And the compiler is giving me this error:
Error:(10, 16) TS7017: Index signature of object type implicitly has an 'any' type.
The Map is 'possible' through es6-shim. I am not quite sure what is going on here. Actually this Map confuses me a little. Map is supposed to come from es6-shim which is supposed to implement es6 functionality. But es6 doesn't have static types, right? So, why the Map expects the key/value types as generic arguments? I have seen some people adding a 'noImplicitAny' flag but I want to solve the problem, not ignore it.
Thank you.
map.get(key)
instead ofmap[key]
. – Enfranchise