我正在做一个使用 typescript 的express项目。我已经设置了控制器和路由器,并有一个方法将我的控制器逻辑 Package 在错误处理程序中。
在我的路由器里。ts文件,post方法会抛出以下错误:
No overload matches this call.
The last overload gave the following error.
Argument of type '(req: Request, res: Response, next: NextFunction) => void' is not assignable to parameter of type 'Application<Record<string, any>>'.
对不起,如果这是一个愚蠢的问题,但我是新的打字和这些类型的错误,我不知道什么是修复。
router.ts
import express from "express";
import { signup } from "../controller/controller.ts";
const authRouter = express.Router();
authRouter.post("/signup", signup);
controller.ts
import { NextFunction, Request ,Response } from "express";
import asyncHandler from "../utils/asyncHandler";
const signup = asyncHandler((req:Request, res:Response, next: NextFunction) => {
res.status(200).json({ message: "signup" });
});
export { signup };
asyncHandler.ts
import { Request, Response, NextFunction } from "express"
const asyncHandler = (fn:any) => (req: Request, res: Response, next: NextFunction) => {
Promise.resolve(fn(req, res, next)).catch(next)
}
export default asyncHandler;
1条答案
按热度按时间cgh8pdjw1#
我想你忘了在路由器中导入路由器。js
或者忘记了应用程序上的实施路线。js