__awaiter is not detected when using async / wait in Typescript

I have the following code snippet in Typescript:

nsp.on('connection', async function (socket) {
    await this.emitInitialPackage(nsp, currentLine, currentCell);
}

emitInitialPackage(nsp: any, name: string, cell: any) {
    return db.Line.find({
        where: {
            name: name,
            CellId: cell
        }
    }).then(results => {
        nsp.emit('value', results);
    }).catch(err => console.log(err));
}

However, when this is compiled (v2.2.1) and executed, I get the following error:

Unlink ReferenceError: __awaiter not defined

What does this mean and how do I get the expected functionality?

Update:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "noEmitHelpers": true,
    "strictNullChecks": false,
    "lib": [
      "dom",
      "es2015.promise", 
      "es5"
    ],
    "types": [
      "node", 
      "express"
    ]
  },
  "exclude": [
    "node_modules",
    "dist"
  ]
}
+3
source share
1 answer

JavaScript (ES6 ), async/await, TypeScript . ES5, -.

:

tsconfig.json noEmitHelpers true. , TypeScript, .

:

  • noEmitHelpers false tsconfig.json, TypeScript , . , , , async/await , 2 ( ).
  • --importHelpers tsc. TypeScript .

: tsc --importHelpers -w

+4

Source: https://habr.com/ru/post/1667652/


All Articles