TypeScript Version: 2.2.1
Code
var arr = ['a', 'b', 'c'];
for (let entry of arr.entries()) {
console.log(entry);
}
// [0, 'a']
// [1, 'b']
// [2, 'c']
for (let idx of arr.keys()) {
console.log(idx);
}
// [0]
// [1]
// [2]
for (let val of arr.values()) {
console.log(val);
}
// ['a']
// ['b']
// ['c']
Tsconfig:
{
"compilerOptions": {
"module": "es2015",
"target": "es5",
"moduleResolution": "node",
"noImplicitAny": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"sourceMap": true,
"experimentalDecorators": true,
"jsx": "react",
"jsxFactory": "h",
"noEmitHelpers": true,
"importHelpers": true,
"pretty": true,
"outDir": "ts-output",
"lib": [
"dom",
"es2015"
]
}
}
Expected behavior:
No errors => this is es2015 standard
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/keys
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/values
Actual behavior:
entries
[ts] Type 'IterableIterator<[number, string]>' is not an array type or a string type.
keys
[ts] Type 'IterableIterator
' is not an array type or a string type.
values
[ts] Type 'IterableIterator
' is not an array type or a string type.
The emit for this feature when targeting ES < 2015 is available in the nightly build
npm i -g typescript@next
It requires that you specify the new compiler option --downlevelIteration.
@aluanhaddad thanks! How do you know about these things before I do 😕
Most helpful comment
@aluanhaddad thanks! How do you know about these things before I do 😕