Typescript gives me this error when I try to Map.values() over the value returned from Map.values() (where the map has type <number, Foo>):
error TS2495: type 'IterableIterator <Foo>' is not an array type or a string type.
According to ES6, doc Map.values() should return an Iterable not an IterableIterator, and I should be able to use it in for a loop.
This works fine in node :
var data = [ {id: 0}, {id: 1}, {id: 3} ]; var m = new Map(data.map(n => [n.id,n])); for(var i of m.values()) { console.log(i) }
This gives an error from tsc :
interface Foo { id: number; } var data: Foo[] = [ {id: 0}, {id: 1}, {id: 2} ]; var m = new Map<number,Foo>(data.map(n => <[number,Foo]>[n.id,n])); for(var i of m.values()) { console.log(i) }
I get Map declarations from @types/ core-js@0.9.34 , so I think the problem is this declaration
Other versions and config:
> tsc --version Version 2.0.3 > cat tsconfig.json { "compilerOptions": { "target": "es6", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "removeComments": false, "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true, "typeRoots": [ "./node_modules/@types/" ] }, "compileOnSave": true, "exclude": [ "node_modules/*", "**/*-aot.ts" ] }