Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type resolution for express ~ 4.21.2 is wrong, pulls @types/express v5 instead of v4 #1007

Open
m-a-rahal-os opened this issue Dec 18, 2024 · 2 comments
Labels

Comments

@m-a-rahal-os
Copy link

m-a-rahal-os commented Dec 18, 2024

Issue

I recently done an upgrade of my packages, namely:

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.

@alexleboucher
Copy link

+1

1 similar comment
@rajephon
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants