Я создаю обработчик маршрута и хочу добавить его в свои маршруты:
import { Request, Response, NextFunction } from "express";
interface IResponse extends Response {
error: (code: number, message: string) => Response;
success: (code: number, message: string, result: any) => Response
}
const routeHandler = (req: Request, res: IResponse, next: NextFunction) => {
res.error = (statusCode: number, errorMessage: string) => res.status(statusCode).json(errorMessage);
res.success = (statusCode: number, message: string, result: any) => res.status(statusCode).json({
message,
result
});
return next();
};
export default routeHandler;
, когда я добавил этот обработчик в файл индекса маршрутов:
import { Router } from "express";
import routeHandler from "../utils/helpers";
const routes = Router();
routes.use(routeHandler);
export default routes;
Iполучил эту ошибку:
No overload matches this call.
The last overload gave the following error.
Argument of type '(req: Request, res: IResponse, next: NextFunction) => void' is not assignable to parameter of type 'PathParams'.
Type '(req: Request, res: IResponse, next: NextFunction) => void' is missing the following properties from type '(string | RegExp)[]': pop, push, concat, join, and 25 more.ts(2769)
index.d.ts(55, 5): The last overload is declared here.