相关疑难解决方法(0)

在Typescript中使用async/await时未定义__awaiter

我在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));
}
Run Code Online (Sandbox Code Playgroud)

但是,当编译(v2.2.1)并运行时,我收到以下错误:

未捕获的ReferenceError:未定义__awaiter

这是什么意思,我如何获得预期的功能?

更新:

{
  "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"
  ]
}
Run Code Online (Sandbox Code Playgroud)

asynchronous async-await typescript

3
推荐指数
2
解决办法
2982
查看次数

标签 统计

async-await ×1

asynchronous ×1

typescript ×1