Have you attempted creating a demo for the TS type of express
? Follow the Type Acquisition guide of TS Playground to manage the imported types by using // types: npm_tag_or_version
.
Despite specifying both versions, none seem to be functioning correctly.
import express, { Request, Response, NextFunction } from 'express'; // types: 4.18.2
// import express, { Request, Response, NextFunction } from 'express'; // types: 4.17.7
const app = express();
const authenticate = (req: Request, res: Response, next: NextFunction) => {
next();
};
app.post('/create', authenticate, (req: Request, res: Response) => { });
Encountered error message:
No overload matches this call.
Overload 1 of 2, '(path: PathParams, ...handlers: RequestHandler[]): Express', gave the following error.
Argument of type '(req: Request, res: Response, next: NextFunction) => void' is not assignable to parameter of type 'RequestHandler'.
Types of parameters 'next' and 'next' are incompatible.
Type 'NextFunction | undefined' is not assignable to type 'NextFunction'.
Type 'undefined' is not assignable to type 'NextFunction'.
Overload 2 of 2, '(path: PathParams, ...handlers: RequestHandlerParams[]): Express', gave the following error.
Argument of type '(req: Request, res: Response, next: NextFunction) => void' is not assignable to parameter of type 'RequestHandlerParams'.
Type '(req: Request, res: Response, next: NextFunction) => void' is not assignable to type 'RequestHandler'.(2769)
TS version: 5.1.3