Home > Back-end >  How to initialize array of Map type?
How to initialize array of Map type?

Time:09-02

I have a simple and fast question, how to initialize an array of Map in TS?

Right now, I'm simply do this like here:

const someMap: Array<Map<string, string>> = new Array<Map<string, string>>();

but I have to use [] instead of Array:

const someMap: Map<string, string>[] = new Map<string, string>[];

can someone tell me why in above example TS throw me this?

Element implicitly has an 'any' type because type 'Map<string, string>' has no index signature. Did you mean to call 'get'?

how to properly initialize Map<string, string>[]?

Thanks for any help!

CodePudding user response:

Arrays can be made with just brackets:

const someMap: Map<string, string>[] = [];

CodePudding user response:

It can be made like this as well:

const someMap: Map<string, string>[] = [new Map<string, string>()]
  • Related