An async function or method in ES5/ES3 requires the ‘Promise‘ constructor. Make sure you have a dec

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.

在这里插入图片描述

原因

Promise仅指类型,但在这里用作值。是否需要更改目标库?尝试将“lib”编译器选项更改为es2015或更高版本

使用tsconfig.json之后无效

在这里插入图片描述
配置了tsconfig之后并无效果

使用命令运行

tsc --target es6 index.ts // index.ts为编译运行的文件名

猜你喜欢

转载自blog.csdn.net/weixin_53191752/article/details/132294439
今日推荐