-
Notifications
You must be signed in to change notification settings - Fork 225
Description
Environment information
Version:
"dependencies": {
"cookie-parser": "^1.4.7",
"express": "^5.1.0",
}
Platform:
Windows 11
Node.js version:
v20.15.1
Bug
No overload matches this call.
The last overload gave the following error.
Argument of type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is not assignable to parameter of type 'PathParams'.ts(2769)
index.d.ts(157, 5): The last overload is declared here.
What steps will reproduce the bug?
Write the following code...
import cookieParser from 'cookie-parser';
import express, {Application} from 'express';
const app: Application = express();
app.use(cookieParser());
The error is caused by Express 5 being more strict with Typescript and wanting return void. You can no longer return anything from your middleware. I've had to replace all code like
return res.status(200);
with
res.status(200);
return // or just get rid of return completely
The only workaround I've found is the following...
app.use(cookieParser() as any);
which is a last resort when using Typescript, as it completely turns off all Typescript type checking.
You need to update this package to work properly with Express 5.