I am currently facing a challenge with using immutable.js alongside TypeScript. The issue lies in convincing the TypeScript compiler that a Map
has an iterator, even though the code runs smoothly in ES6. I am perplexed as to why it does not function correctly in TypeScript.
Code Snippet:
import {Map} from "immutable";
const m = Map({ a: 1 });
for (const [key, value] of m) {
console.log(key, value);
}
Expected Output:
a 1
Actual Outcome:
TSError: ⨯ Unable to compile TypeScript
src/test.ts (6,28): Type must have a '[Symbol.iterator]()' method that returns an iterator. (2488)
Equivalent ES6 illustration:
const Immutable = require( "immutable");
const m = Immutable.Map({ a: 1 });
for (const [key, value] of m) {
console.log(key, value);
}
Output Displayed:
a 1
Additional Remarks:
Attempts with m.entries()
and m.entrySeq()
yield similar errors.
My TypeScript version is 2.0.3