expressjs / expressjs/cookie-parser
"No overload matches this call" using cookieParser with Express 5 and Typescript
- Dominant language
- JavaScript
- Stars
- 2k
- Forks
- 234
- PR merge metrics
- No merged PRs in 30d
Description
## Environment information
**Version**:
```json
"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>' 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...
```javascript
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
```javascript
return res.status(200);
```
with
```javascript
res.status(200);
return // or just get rid of return completely
```
The only workaround I've found is the following...
```javascript
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.
Contributor guide
Assessment
This issue has not been assessed yet.