3
我有下面的代碼片段在打字稿:__awaiter沒有定義/等待在打字稿
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));
}
然而,當這編譯(V2.2.1)並運行,我得到以下錯誤:
Uncaught ReferenceError: __awaiter is not defined
這是什麼意思?我如何獲得預期的功能?
更新:
{
"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"
]
}
你能分享你的'tsconfig.json'?以及您用來編譯代碼的命令。 – Romain
@Romain當然 - [這裏](https://gist.github.com/georgeedwards/755fd6a6561a245bac55bf51b8493a51)就是tsconfig,我只用'tsc -w'從tsconfig目錄下運行它。 –
如果發佈的答案可解決您的問題,請將其標記爲已接受 – Romain