Categories
TypeScript Answers

How to fix the “An async function or method in ES5/ES3 requires the ‘Promise’ constructor” with TypeScript?

Spread the love

Sometimes, we want to fix the "An async function or method in ES5/ES3 requires the ‘Promise’ constructor" with TypeScript.

In this article, we’ll look at how to fix the "An async function or method in ES5/ES3 requires the ‘Promise’ constructor" with TypeScript.

How to fix the "An async function or method in ES5/ES3 requires the ‘Promise’ constructor" with TypeScript?

To fix the "An async function or method in ES5/ES3 requires the ‘Promise’ constructor" with TypeScript, we can add the 'es2015' into the compilerOptions.lib array.

For instance, we write

{
  //...
  "compilerOptions": {
    "lib": ["es2015"]
  }
  //...
}

to set compilerOptions.lib to ["es2015"] so that the TypeScript compiler can assume that the Promise constructor is available globally in our project.

Conclusion

To fix the "An async function or method in ES5/ES3 requires the ‘Promise’ constructor" with TypeScript, we can add the 'es2015' into the compilerOptions.lib array.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *