我正在研究ng2实现.我正在使用以下函数调用将对象转换为数组:
var authors = Object.entries(responseObject.Authors);
Run Code Online (Sandbox Code Playgroud)
这是标准的js功能.但是,ts编译器返回以下错误:
"Property 'entries' does not exist on type 'ObjectConstructor'"
Run Code Online (Sandbox Code Playgroud)
基于快速谷歌,似乎解决方案可能是将compilerOptions目标属性从es5更改为es6.但是,在之前的一个问题的一些先前的研究之后,我认为我能够通过在我的tsconfig.json上包含额外的"lib"属性来利用es6功能:
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "commonjs",
"noEmitOnError": true,
"noImplicitAny": false,
"outDir": "../Scripts/",
"removeComments": false,
"sourceMap": true,
"target": "es5",
"moduleResolution": "node",
"lib": [
"es2015",
"dom"
]
}
Run Code Online (Sandbox Code Playgroud)
我也尝试将目标属性更改为es2015,然后重建项目并执行"typescriptUsingTsConfig",但我仍然得到相同的错误.知道我可以在这里做什么来利用Object.entries()函数?