无法转换包含异步等待的TypeScript [英] Cannot transpile TypeScript containing async await

查看:96
本文介绍了无法转换包含异步等待的TypeScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试转换以下包含asyncawait关键字的TypeScript代码

When trying to transpile the following TypeScript code containing async and await keywords

async function foo() {
    await bar();
}

我收到以下错误

src/aa.ts(1,7): error TS1005: ';' expected.
src/aa.ts(2,11): error TS1005: ';' expected.

结果是具有此内容的.js文件

The result is a .js file with this content

async;
function foo() {
    await;
    bar();
}

我正在使用以下tsc选项:-t es6 -m commonjs,遵循此MSDN博客.我已经安装了TypeScript 1.8.9.

I'm using these tsc options: -t es6 -m commonjs, following instructions on this MSDN blog. I have TypeScript 1.8.9 installed.

有什么想法吗?

推荐答案

由于某种原因,TypeScript编译器无法识别asyncawait关键字.即使TypeScript编译器版本是正确的版本,也会发生这种情况.

For some reason the TypeScript compiler did not recognize the async and await keywords. This happened even though the TypeScript compiler version was of the correct version.

我要解决的问题是卸载tsc并全局安装打字稿:

What I did to solve this is uninstall tsc and install typescript globally:

npm uninstall --global tsc
npm install --global typescript

这篇关于无法转换包含异步等待的TypeScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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