Skip to content

Compression middleware causes TypeScript typing error #223

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

Closed
rjray opened this issue Mar 9, 2025 · 8 comments
Closed

Compression middleware causes TypeScript typing error #223

rjray opened this issue Mar 9, 2025 · 8 comments

Comments

@rjray
Copy link

rjray commented Mar 9, 2025

Using Express and Compression in a TypeScript project, I see the following error in VS Code:

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(153, 5): The last overload is declared here.

Environment information

Version:

Platform:

Linux tremere 6.11.0-19-generic #19~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Feb 17 11:51:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

Node.js version:

v22.12.0

Any other relevant information:
This only surfaced a month or two ago, after not being an error. The application does actually work, with compression enabled (tested in an API test utility). It's just the erroneous error flag that is an issue.

What steps will reproduce the bug?

I have reproduced this on both the Linux system I am currently using, and on MacOS. The repo that is exhibiting this is rjray/smdb, specifically the server sub-project.

The app.ts file in which this occurs is attached (as app.ts.txt due to GH limitations).

app.ts.txt

@rjray rjray added the bug label Mar 9, 2025
@bjohansebas
Copy link
Member

cc @RobinTail @hichemfantar Can you help us here, please? It looks like it's just a type error.

@RobinTail
Copy link

I believe it's important to reflect versions of the dependencies in that case

"compression": "^1.8.0",
"express": "^4.21.2",
"@types/compression": "^1.7.5",
"@types/express": "^4.17.21",

I'm gonna try to make a smaller code sample that could possibly reproduce the issue, @bjohansebas
But so far I didn't experience anything like that using compression with express

@RobinTail
Copy link

RobinTail commented Mar 11, 2025

I found the cause — it's the duplicated types of express having different versions, @rjray && @bjohansebas

$ yarn why @types/express

[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.79MB"
info Number of shared dependencies: 7
=> Found "@types/compression#@types/[email protected]"
info This module exists because "@types#compression" depends on it.
info Disk size without dependencies: "20KB"
info Disk size with unique dependencies: "128KB"
info Disk size with transitive dependencies: "2.79MB"
info Number of shared dependencies: 7

@RobinTail
Copy link

Here is what fixes the issue in your project, @rjray

Add the following lines to your package.json and run yarn

  "resolutions": {
    "**/@types/express": "^4"
  },

@rjray
Copy link
Author

rjray commented Mar 11, 2025

Here is what fixes the issue in your project, @rjray

Add the following lines to your package.json and run yarn

"resolutions": {
"**/@types/express": "^4"
},

Perfect, that worked. Thank you!

@rjray rjray closed this as completed Mar 11, 2025
@bjohansebas
Copy link
Member

@RobinTail thanks for the help. since the new version of Express types was released, the ecosystem has been splitting a bit due to differences in types and versions.

@hichemfantar
Copy link

thanks for the fix @RobinTail hopefully these issues will go away once we start bundling types with express

@RobinTail
Copy link

I'm not sure @hichemfantar ,
because what I'm doing in the corresponding PR targets express v5, but users of v4 (which is still labeled latest) would have still to install @types/express where latest points to the types of v5.
Same for @types/compression having

"dependencies": {
        "@types/express": "*"
    },

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

No branches or pull requests

4 participants