Billy
Billy

Reputation: 193

How to initialize array of Map type?

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!

Upvotes: 0

Views: 229

Answers (2)

tenshi
tenshi

Reputation: 26324

Arrays can be made with just brackets:

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

Upvotes: 4

imoxto
imoxto

Reputation: 143

It can be made like this as well:

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

Upvotes: 3

Related Questions