__awaiter没有定义

我在VSCode中使用typescript v 1.8.9,nodejs 5.9.1我有我的文件app.ts有这些行

import {XController} from "./XController"; var xContrller=new XController(); xContrller.CallAsyncMethod(some args"); 

而XController是一个具有asynchronous方法CallAsyncMethod的类

喜欢这个

 public async CallAsyncMethod(url: string) { await this.request.post(url); } 

这在JavaScript中翻译为__awaiter(void,…),但它崩溃,说__awaiter没有定义? 任何线索为什么发生这种情况,以及如何解决这个问题。

谢谢

你的tsconfig.json很可能是错误的。 下面的工作很好:

tsconfig.json

 { "compilerOptions": { "target": "es6", "module": "commonjs", "sourceMap": true }, "exclude": [ "node_modules", "typings/browser", "typings/browser.d.ts" ], "compileOnSave": true } 

ping.ts

 export async function ping() { for (var i = 0; i < 10; i++) { await delay(300); console.log("ping"); } } function delay(ms: number) { return new Promise(resolve => setTimeout(resolve, ms)); } 

main.ts

 import {ping} from "./ping" async function main() { await ping(); } main();