Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

__awaiter is not defined

I'm using typescript v 1.8.9 in VSCode, nodejs 5.9.1 i have my file app.ts that has these lines

import {XController} from "./XController";

var xContrller=new XController();
xContrller.CallAsyncMethod(some args");

and XController is a class having async methode CallAsyncMethod

like this

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

this translates to __awaiter(void,...) in javascript but it crashes saying that __awaiter is not defined ??? any clues why this is happening and how to fix it.

Thanks

like image 850
Ahmed Avatar asked Oct 30 '22 06:10

Ahmed


1 Answers

your tsconfig.json is most likely wrong. The following worked just fine:

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();
like image 130
basarat Avatar answered Nov 11 '22 17:11

basarat