在不转换异步函数的情况下编译打字稿

Compile typescript without transpiling async functions

有没有办法使用 TypeScript 编译器只删除类型注释,而不转译异步函数?像 { target: 'esInfinite' } 选项?原因是:有些浏览器已经支持异步功能,所以我希望有一个不影响这些功能的构建目标。

示例输入:

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

示例输出:

async function foo(a) {}

此功能已被请求 here. Targeting es2016 and es2017 should be available in the Community milestone and in TypeScript 2.1

在您的 tsconfig.json 中,将您的目标更改为 ES2017,然后它将保留 async/await

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

请确保您的 运行-time 原生支持!!!

PS:从 Apr 2018 开始,AWS Lambda 现在支持 Nodejs 8。您应该可以使用上面的配置。