我在使用TypeScript转换ES7代码时遇到了问题。此代码:TypeScript中的ES7 Object.entries()不起作用
const sizeByColor = {
red: 100,
green: 500,
};
for (const [ color, size ] of Object.entries(sizeByColor)) {
console.log(color);
console.log(size);
}
给出了错误:
TypeError: Object.entries is not a function
打字稿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"
]
}
我想要遍历槽对象与Object.entries()
,所以我分配了内部定义"lib": [ "es2017" ]
,但是,打字稿不会允许我传译它。
欢迎来到SO :)请介绍你的问题......你的问题的一个问题或一个条目,详细说明你正在使用什么。添加你做过什么,做过什么,不做过什么的例子。谢谢 – Benj
嗨,好些? :-) –
是的:)对不起,有点迂腐,但不用担心,当我来到这里时,我也有很多呕吐;)不要忘记把所有相关/帮助你,并标记为接受当一个答案符合你的需求。谢谢 ! – Benj