I am trying to custom my own Response interface to extends some methods instead of using default Response type of Express.js but I am getting an TypeScript error:
The last overload gave the following error. Argument of type ‘(req:
Request, res: CustomResponse, next: NextFunction) => void’ is not
assignable to parameter of type ‘PathParams’.ts(2769)
I have researched many different ways to solve this issue such as: declare namespace
but it didn’t really work for me so I decided to choose another way which is custom my interface that extending from Response interface of Express.js. Below is my code:
import { Response } from 'express';
interface CustomResponse extends Response {
myMethod: () => void;
}
...
app.use((req: Request, res: CustomResponse, next: NextFunction) => { // <=== error causing from CustomResponse
res.myMethod();
});