用TypeScript编写异步代码
async function run() {
await sleep(500);
}
在运行时,会提示 __awaiter is not defined
出现这种情况,需要校对一下tsconfig.ts配置
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noEmitHelpers": false,
"sourceMap": true,
},
}
1.target设置为es6
2.noEmitHelpers设置为false
重新编译TS代码后,问题解决。
本文介绍了如何在TypeScript中使用async/await编写异步代码,并阐述了遇到'__awaiter is not defined'错误时,通过调整tsconfig.ts配置(将target设为es6并启用emitHelpers)来解决问题的方法。
694

被折叠的 条评论
为什么被折叠?



