@types/xxxx package and had problems.Definitions by: in index.d.ts) so they can respond.I'm having the current problem using @types/express 4.11.1 & TSC 2.8.3.
The following code cannot compile:
function aMiddleware(req: Request, res: Response, next: NextFunction) {
next();
}
app.get('/foo/bar', aMiddleware);
I get the following error:
TS2345: 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 | ErrorRequestHandler)[]'.
Property 'includes' is missing in type '(req: Request, res: Response, next: NextFunction) => void'.
Hi Jimmy,
You need to import like this...
import { Express, Request, Response, NextFunction } from 'express';
const express = require('express');
const app: Express = express();
function aMiddleware(req: Request, res: Response, next: NextFunction) {
next();
}
app.get('/foo/bar', aMiddleware);
The reason is Request, Response, NextFunction of Node.js are not the same as Express.
Hope this helps.
Thanks, I'll give that a try!
This works great. Thanks muchly, again.
Most helpful comment
Hi Jimmy,
You need to import like this...
The reason is
Request,Response,NextFunctionof Node.js are not the same as Express.Hope this helps.