solowt
solowt

Reputation: 73

Declaring Maps with typescript

private itemsMap: Map<Array<string>,string> = new Map([
    [['shp'], 'Shapefile'],
    [['doc', 'docx'], 'Microsoft Word']
]);

Typescript doesn't like this, it gives me: "Argument of type '(string | string[])[][]' is not assignable to parameter of type 'Iterable<[{},{}]>"

This is a valid way to declare a "Map literal" though. Is there a way to do this that isn't going to cause an issue?

Upvotes: 3

Views: 4746

Answers (1)

David Driscoll
David Driscoll

Reputation: 1419

What TypeScript version are using? This appears to work correctly with the current TypeScript version (currently 2.2.x).

See this playground

Upvotes: 1

Related Questions