如何在 TypeScript 中使用 Object.entries?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42410029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I make Object.entries available in TypeScript?
提问by user776686
In my angular-cli-built app (which is currently using TypeScript 2.0.3) I want to be able to use this decomposition-based iterator:
在我的 angular-cli 构建的应用程序(目前使用的是 TypeScript 2.0.3)中,我希望能够使用这个基于分解的迭代器:
for (let [key, value] of Object.entries(obj)) {
}
What do I have to do in order to have it recognized:
我该怎么做才能让它被认可:
- upgrade TypeScript?
- use a polyfill?
- if so: how do I import it - in individual .ts files or in a config file to make it globally available?
- use a third-party library?
- 升级打字稿?
- 使用polyfill?
- 如果是这样:我如何导入它 - 在单独的 .ts 文件或配置文件中以使其全局可用?
- 使用第三方库?
回答by Günter Z?chbauer
You need to add
你需要添加
"lib": [ "es2017.object" ]
https://github.com/Microsoft/TypeScript/issues/8482#issuecomment-262847071
https://github.com/Microsoft/TypeScript/issues/8482#issuecomment-262847071