【发布时间】:2022-02-03 09:03:20
【问题描述】:
我是 TypeScript 的新手,目前陷入困境。我有一个 nodejs 和 express 应用程序。
我收到以下错误:没有重载匹配此调用。
The last overload gave the following error.
Argument of type '{ isLoggedIn: (req: Request<ParamsDictionary, any, any, QueryString.ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction) => Response<...> | undefined; }' is not assignable to parameter of type 'RequestHandlerParams<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
Type '{ isLoggedIn: (req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction) => Response<...> | undefined; }' is missing the following properties from type '(ErrorRequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>> | RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<...>>)[]': length, pop,
这是我的路线文件
export {}
import express, { Router } from 'express';
import lessons from '@controllers/lessons';
import isLoggedIn from '@middleware/user';
const lessonRoutes: Router = express.Router();
lessonRoutes.route('/')
.get(isLoggedIn, lessons.lessonForm)
这是我的中间件文件
import { Request, Response, NextFunction } from 'express';
const isLoggedIn = (req: Request, res: Response, next: NextFunction) => {
if (!req.isAuthenticated()) {
return res.status(401).json({
error: "User must sign in"
})
}
next();
}
export default {
isLoggedIn
}
【问题讨论】:
标签: node.js typescript express passport.js