Búsqueda de sitios web

node.js - __awaiter no está definido


Estoy usando TypeScript v 1.8.9 en VSCode, Node.js 5.9.1. Tengo mi archivo app.ts que tiene estas líneas

import {XController} from "./XController";

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

y XController es una clase que tiene un método asincrónico CallAsyncMethod

así

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

esto se traduce a __awaiter(void,...) en javascript pero se bloquea diciendo que __awaiter no está definido ??? ¿alguna idea de por qué está pasando esto y cómo solucionarlo.

Gracias

Respuesta #1

tu tsconfig.json probablemente está mal. Lo siguiente funcionó perfectamente:

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();

Artículos relacionados