【发布时间】:2018-03-21 20:35:06
【问题描述】:
在我的快递应用中,我有以下中间件:
app.use(function(req, res, next) {
let _end = res.end;
res.end = function end(chunk, encoding) {
...
return _end.call(res, chunk, encoding);
};
next();
});
这会返回以下打字稿错误:
错误 TS2322: 类型 '(chunk: any, encoding: any) => any' 不是 可分配给类型 '{ (): void; (缓冲区:缓冲区,cb?:函数):无效; (str: string, cb?: Function): void; (str:stri ...'。
在@types/node/index.d.tsend方法中是这样描述的:
end(): void;
end(buffer: Buffer, cb?: Function): void;
end(str: string, cb?: Function): void;
end(str: string, encoding?: string, cb?: Function): void;
end(data?: any, encoding?: string): void;
修复此错误的正确类型是什么?
【问题讨论】:
标签: typescript express