Tobias Stangl Tobias Stangl - 10 days ago 6
TypeScript Question

error TS2345: Argument of type 'Map<String, boolean>' is not ass ignable to parameter of type 'IterableShim<[String, boolean]>'

i have the following typescript code snippet:

setSelection(selection: Map<String, boolean>) {
this.selection = new Map<String, boolean>(selection);
}


But this gives me the following error:


error TS2345: Argument of type 'Map' is not ass
ignable to parameter of type 'IterableShim<[String, boolean]>'.
Property '"es6-shim iterator"' is missing in type 'Map'.


What am i doing wrong (the code is working though)?

I am using typings with the es6-shim Type descriptions (https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/es6-shim).

Many thanks,

Tobias

Answer

I solved it by calling the "entries()" method of the map. This provides an iterable which the Map constructor awaits.

setSelection(selection: Map<String, boolean>) {
    this.selection = new Map<String, boolean>(selection.entries());
}