question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Helmet + Express + Typescript = No overload matches this call error

See original GitHub issue

Issue similar to: #324

My versions:

helmet@4.6.0
express@4.17.1
@types/express@4.17.13
@types/node@16.3.0
typescript@4.3.5
node@16.4.2

My code:

import express from "express";
import helmet from "helmet";
import cors from "cors";

const app = express();

app.use(helmet());
app.use(cors());
app.use(express.json());

tsconfig

{
  "compilerOptions": {
    "lib": ["es2020"],
    "module": "commonjs",
    "target": "es2020",

    "strict": true,
    "esModuleInterop": true,
    "sourceMap": true,
    "outDir": "dist"
  },
  "include": ["**/*.ts", "./client/**/*"]
}

Error:

No overload matches this call. The last overload gave the following error. Argument of type ‘(req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => void’ is not assignable to parameter of type ‘PathParams’. Type ‘(req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => void’ is missing the following properties from type ‘(string | RegExp)[]’: pop, push, concat, join, and 27 more.ts(2769)

I was able to workaround by making this change: app.use(helmet() as express.RequestHandler);

I have the same issue with the app.use(express.json());, so not sure if this is related with helmet at all.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

10reactions
cehenriquescommented, Jul 13, 2021

I downgraded some packages and found out that the issue is with @types/node. I was using the latest version, v16.3.1, and when I downgraded to v14.17.4 the errors disappeared.

EDIT: After further investigation, the errors start to show up when using @types/node v15.9.0 or higher.

2reactions
0x80commented, Aug 24, 2021

15.9.x still gives me errors on bodyParser.json() and helmet() 15.6.x is 👌 for me

Read more comments on GitHub >

github_iconTop Results From Across the Web

Express errors with typescript - Stack Overflow
and I'm getting errors on both the helmet() and express.json() calls: helmet(): No overload matches this call. The last overload gave the ...
Read more >
No Overload matches this call error (typescript/nodejs7express)
I created a controller: import { Request, Response } from "express"; export const signIn = async (req: Request, res: Response) => { try ......
Read more >
No overload matches this call error in TypeScript | bobbyhadz
The error "No overload matches this call" occurs when we call a function and pass it a parameter that doesn't match any of...
Read more >
How to repair a 'TS2769: No overload matches this call'-Reactjs
My colleague eventually taught me a workaround: Exclude the corresponding action, e.g. takeEvery from the original import statement.
Read more >
helmet - Bountysource
how to configure Helmet to ignore some requests (pattern match)? ... The following headers are not set when you call helmet() with no...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found