Cannot move TypeScript containing async wait

When trying to pass 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 use these tsc options: -t es6 -m commonjs , following the instructions on this MSDN blog . I have TypeScript 1.8.9 installed.

Any ideas?

+6
source share
2 answers

For some reason, the TypeScript compiler did not recognize the async and await keywords. This happened, although the TypeScript compiler version had the correct version.

What I did to solve this problem is to remove tsc and install TypeScript globally:

 npm uninstall --global tsc npm install --global typescript 
+3
source

I ran into a similar issue with the asynchronous arrow function:

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

Typescript was happy as soon as I wrapped my function parameter in parentheses:

async (resource_type) => some_value

+1
source

All Articles