Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile typescript without transpiling async functions

Is there a way to use the TypeScript compiler only to remove type annotations, but not transpiling async functions? Something like a { target: 'esInfinite' } option? The reason is: There are browsers that already support async functions, so I wish to have a build target where those functions are not affected.

example input:

async function foo(a : number) : Promise<void> {}

example output:

async function foo(a) {}
like image 605
Tamas Hegedus Avatar asked Oct 07 '16 14:10

Tamas Hegedus


1 Answers

In your tsconfig.json, change your target to ES2017, then it will preserve the async/await.

{
  "compilerOptions": {
    .....
    "target": "ES2017",
    .....
  }
}

DO make sure your run-time supports it natively!!!

PS: as of Apr 2018, AWS Lambda now supports Nodejs 8. You should be able to use the above config for it.

like image 196
LeOn - Han Li Avatar answered Oct 14 '22 11:10

LeOn - Han Li