ts An async function or method in ES5/ES3 requires the 'Promise' constructor

匿名 (未验证) 提交于 2019-12-03 01:47:02

问题:

Hello I'm Using async/await in my TypeScript Project, But I Get this log:

[ts] An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option.

How Can I Solve That?

回答1:

As the error message says, add lib: es2015 to your tsconfig.json

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


回答2:

Try this package which contains type definitions for es6-promise

npm install --save @types/es6-promise



回答3:

If you are on VS, delete the tsconfig.json and right click open Properties->TypeScript Build in General change the followings

  • ECMAScript version: ECMAScript 6

  • Module System: ES2015



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!