Open
Description
Issue
I recently done an upgrade of my packages, namely:
- from
[email protected]
to[email protected]
- from
[email protected]
to[email protected]
And I noticed that there are some typing issues (I'm not alone, see this issue in express).
Solution / TL;DR
As stated in this answer the problem is that express-session is wrongly pulling @types/express@5
instead of ^4.17.5
, when running yarn why @types/express
I get:
yarn why @types/express 07:39:00
yarn why v1.22.22
[1/4] Why do we have the module "@types/express"...?
[2/4] Initialising dependency graph...
[3/4] Finding dependency...
[4/4] Calculating file sizes...
=> Found "@types/[email protected]"
info Has been hoisted to "@types/express"
info This module exists because it's specified in "devDependencies".
info Disk size without dependencies: "20KB"
info Disk size with unique dependencies: "128KB"
info Disk size with transitive dependencies: "2.76MB"
info Number of shared dependencies: 7
=> Found "@types/express-session#@types/[email protected]"
info This module exists because "@types#express-session" depends on it.
info Disk size without dependencies: "20KB"
info Disk size with unique dependencies: "128KB"
info Disk size with transitive dependencies: "2.76MB"
info Number of shared dependencies: 7
Done in 0.28s.
The solution was to (again, thanks to this answer) to force "resolutions" (or "overrides" for nmp) in package.json as follows:
"resolutions": {
"**/@types/express": "^4.17.21"
}
How to reproduce
Create a project with the following dependencies (package.json):
{
"dependencies": {
"express": "^4.19.2",
"express-session": "^1.18.0",
},
"devDependencies": {
"@types/express": "^4.17.21",
"@types/express-session": "^1.18.0",
"typescript": "^5.4.3"
}
And this code
// index.ts
import session from "express-session";
import express from "express";
const app = express();
app.use(
session({ /* session details */ }) // <--- error on this line
);
I get the following error No overload matches this call. Argument of type 'RequestHandler<ParamsDictionary, any, any, ParsedQs, Record<string, any>>' is not assignable to parameter of type 'PathParams'.ts(2769)
Thanks for your time.