我正在尝试使用Promise.allSettled,但我一直保持TSLint的geeting错误
我使用:
这是我的tsconfig:
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"typeRoots": ["node_modules/@types"],
"lib": ["es2015", "dom"],
"paths": {
"@ing/*": ["src/app/features/*"]
}
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
这是TSlint标记错误的地方:
Promise.allSettled(loadingPromises).then(results=>{
results.forEach( (status, value) =>{
console.log(status,value);
})
});
Te代码运行完美,TSlint引发的错误是:
TS2339:类型“ PromiseConstructor”上不存在属性“ allSettled”。
答案 0 :(得分:2)
在这里回答问题: https://stackoverflow.com/a/60276174/11057988
建议的解决方法:
declare interface PromiseConstructor {
allSettled(promises: Array<Promise<any>>): Promise<Array<{status: 'fulfilled' | 'rejected', value?: any, reason?: any}>>;
}