我在 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 是一个具有异步方法 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();
关于node.js - __awaiter 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36270437/