0

I'm trying to use Promise.allSettled but I keep geeting errors from TSLint

I use:

  • angular 9
  • Typescript 3.8.3
  • node 13.9.0

This is my 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
    }
}

This is where TSlint mark the error:

 Promise.allSettled(loadingPromises).then(results=>{
      results.forEach( (status, value) =>{
        console.log(status,value);
      })
    });

Te code runs perfectly ,The error TSlint throws is:

TS2339: Property 'allSettled' does not exist on type 'PromiseConstructor'.

Nasgar
  • 859
  • 2
  • 11
  • 26
  • 1
    What errors? What is the code that's causing errors? Please provide a [minimal, reproducible example](/help/minimal-reproducible-example). – D. Pardal Jun 03 '20 at 07:36

1 Answers1

2

The question is answered here: https://stackoverflow.com/a/60276174/11057988

Suggested workaround:

declare interface PromiseConstructor {
    allSettled(promises: Array<Promise<any>>): Promise<Array<{status: 'fulfilled' | 'rejected', value?: any, reason?: any}>>;
}
Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32