0

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!

2 Answers 2

4

Arrays can be made with just brackets:

const someMap: Map<string, string>[] = [];
Sign up to request clarification or add additional context in comments.

1 Comment

Relevant documentation: this is an array literal
3

It can be made like this as well:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.