【发布时间】:2020-02-26 02:13:36
【问题描述】:
我正在为我的后端代码库转换 Typescript,但是在收听 http 服务器 Error Event 时,我遇到了关于 [ts] property syscall does not exist on error 的问题。我认为这里的 Error 类型是错误的,但是显然 Node.js 没有为这个回调函数提供默认的错误类型。任何人都可以帮助我正确的错误类型吗?
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World!');
res.end();
})
server.listen(3000);
server.on('error', onError);
function onError(error: Error) {
// [ts] property syscall does not exist on error
if (error.syscall !== 'listen') {
throw error;
}
}
【问题讨论】:
标签: node.js typescript