Issue
I recently done an upgrade of my packages, namely:
- from
express-session@1.18.0 to express-session@1.18.1 - from
express@4.19.2 to express@4.21.2
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/express@4.17.21"
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/express@5.0.0"
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.tsimportsessionfrom"express-session";importexpressfrom"express";constapp=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.
Issue
I recently done an upgrade of my packages, namely:
express-session@1.18.0toexpress-session@1.18.1express@4.19.2toexpress@4.21.2And 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@5instead of^4.17.5, when runningyarn why @types/expressI get:The solution was to (again, thanks to this answer) to force "resolutions" (or "overrides" for nmp) in package.json as follows:
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
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.