Cannot transpile TypeScript containing async await

我是研究僧i 提交于 2019-12-07 03:09:59

问题


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

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

I get the following error

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

The result is a .js file with this content

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

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

Any ideas?


回答1:


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.

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

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



回答2:


I encountered a similar issue with an asynchronous arrow function:

async resource_type => some_value
// error TS1005: ',' expected.

Typescript was happy once I wrapped my function parameter in parenthesis:

async (resource_type) => some_value



来源:https://stackoverflow.com/questions/36423600/cannot-transpile-typescript-containing-async-await

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