【发布时间】:2020-06-02 04:27:54
【问题描述】:
我正在尝试将 Promise.allSettled API 与 TypeScript 一起使用。代码在这里:
server.test.ts:
it('should partial success if QPS > 50', async () => {
const requests: any[] = [];
for (let i = 0; i < 51; i++) {
requests.push(rp('http://localhost:3000/place'));
}
await Promise.allSettled(requests);
// ...
});
但是 TSC 抛出错误:
类型“PromiseConstructor”.ts(2339) 上不存在属性“allSettled”
我已经将这些值添加到tsconfig.json 中的lib 选项中:
tsconfig.json:
{
"compilerOptions": {
/* Basic Options */
"target": "ES2015" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [
"ES2015",
"ES2016",
"ES2017",
"ES2018",
"ES2019",
"ES2020",
"ESNext"
]
// ...
}
TypeScript 版本:"typescript": "^3.7.3"
那么,我该如何解决呢?我知道我可以使用替代模块,但我对原生使用 TypeScript 感到好奇。
【问题讨论】:
标签: javascript typescript es6-promise