【发布时间】:2019-08-27 11:17:38
【问题描述】:
Promise.all<any, any>(ajaxRequests).then(()=> {
console.log("done");
});
以上代码给出以下编译错误:
TS2585: 'Promise' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.
我不熟悉这个编译器 lib 选项是什么以及如果我要更改它会产生什么影响。
我正在尝试针对较旧的浏览器并且需要支持 es5 我相信。我认为这可以通过转译/polyfilling来完成?我的打字稿配置是:
{
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"declaration": true,
"removeComments": false,
"module" : "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
},
"include": [
"src/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
【问题讨论】:
-
你应该添加类似@types/es6-promise的东西
标签: typescript ecmascript-6 promise es5-compatiblity