ts ES5/ES3中的异步函数或方法需要'Promise'构造函数 [英] ts An async function or method in ES5/ES3 requires the 'Promise' constructor

查看:1061
本文介绍了ts ES5/ES3中的异步函数或方法需要'Promise'构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我在TypeScript项目中使用async/await,但是我得到了以下日志:

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

[ts] ES5/ES3中的异步函数或方法需要'Promise'构造函数.确保您具有"Promise"构造函数的声明,或者在--lib选项中包含"ES2015".

[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.

我该如何解决?

推荐答案

如错误消息所述,将lib: es2015添加到您的tsconfig.json

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

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

更新:如果这对您不起作用,请尝试以下操作:

UPDATE: if this doesn't work for you, try this:

JetBrains IDE(例如WebStorm)在默认情况下使用其自己的实现.确保将其配置为使用TypeScript语言服务.

JetBrains IDE such as WebStorm, use its own implementation by default. Make sure you configure it to use TypeScript language service instead.

对于Visual Studio,项目文件和tsconfig.json是互斥的.您将需要直接配置项目.

For Visual Studio, the project files and tsconfig.json are mutually exclusive. You will need to configure your project directly.

https://github.com/Microsoft/TypeScript/issues/3983# issuecomment-123861491

这篇关于ts ES5/ES3中的异步函数或方法需要'Promise'构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆