I'm encountering an issue with the middleware in my express app. Here is the code:
app.use(function(req, res, next) {
let _end = res.end;
res.end = function end(chunk, encoding) {
...
return _end.call(res, chunk, encoding);
};
next();
});
However, I am facing a typescript error which states:
error TS2322: Type '(chunk: any, encoding: any) => any' is not assignable to type '{ (): void; (buffer: Buffer, cb?: Function): void; (str: string, cb?: Function): void; (str: stri...'.
The end
method in @types/node/index.d.ts
is described as follows:
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;
What would be the correct type to resolve this error?