I have an issue with transpiling ES7 code with TypeScript. This code:
const sizeByColor = {
red: 100,
green: 500,
};
for ( const [ color, size ] of Object.entries(sizeByColor) ) {
console.log(color);
console.log(size);
}
gives the error:
TypeError: Object.entries is not a function
TypeScript v2.0.3
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": true,
"noEmitOnError": true,
"outDir": "dist",
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"pretty": true,
"lib": [ "es2017" ],
},
"exclude": [
"node_modules"
],
"include": [
"./node_modules/@types/**/*.d.ts",
"./src/**/*.ts"
]
}
I want to iterate trough object with Object.entries()
, so I assigned internal definitions "lib": [ "es2017" ]
, but still, typescript wont allow me to transpile it.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…