Helmet + Express + Typescript = No overload matches this call error
See original GitHub issueIssue 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:
- Created 2 years ago
- Reactions:3
- Comments:15 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
15.9.x still gives me errors on bodyParser.json() and helmet() 15.6.x is 👌 for me