我在使用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