Typescript is giving me this error when I try to iterate 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 the ES6 doc Map.values() should return an Iterable not an IterableIterator and I should be able to use it in a for-of 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 the 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'm getting Map declarations from @types/[email protected] so I guess the issue is in this declaration??
Other version & conf info:
> 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"
]
}