小编Jan*_*žal的帖子

TypeScript中的ES7 Object.entries()不起作用

我有使用TypeScript转换ES7代码的问题.这段代码:

const sizeByColor = {
    red: 100,
    green: 500,
};

for ( const [ color, size ] of Object.entries(sizeByColor) ) {
    console.log(color);
    console.log(size);
}
Run Code Online (Sandbox Code Playgroud)

给出错误:

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"
]
}
Run Code Online (Sandbox Code Playgroud)

我想通过对象迭代Object.entries(),所以我分配了内部定义"lib": [ "es2017" ],但仍然,typescript不允许我转换它.

typescript

18
推荐指数
4
解决办法
2万
查看次数

标签 统计

typescript ×1