I'm trying to use the Promise.allSettled
API with TypeScript. Code here:
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);
// ...
});
But TSC throws an error:
Property 'allSettled' does not exist on type 'PromiseConstructor'.ts(2339)
I already added these values to the lib
option in tsconfig.json
:
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 version: "typescript": "^3.7.3"
So, how can I solve this? I know I can use an alternative module, but I am curious about working with TypeScript natively.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…