Using helmet for express in a TS project causes a type error
samerbuna opened this issue · comments
Samer Buna commented
Versions used:
helmet@4.6.0
express@4.17.1
@types/express@4.17.9
typescript@4.3.5
Code:
import express from "express"
import helmet from "helmet"
const app = express()
app.use(helmet())
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)
index.d.ts(69, 5): The last overload is declared here.
(alias) helmet(options?: Readonly<HelmetOptions> | undefined): (req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => void
import helmet
Evan Hahn commented
Sorry you're running into this.
- Could you include your tsconfig.json so I can replicate the issue?
- Does
import helmet = require('helmet')
work for you?
Samer Buna commented
Apologies. This was caused by an incompatible @types/node
package. The error was not helpful but I guess the blame is on TS for this one.
Thanks Evan!
Evan Hahn commented
Glad your problem was resolved!
Feel free to open a new issue if anything else comes up.
Carlos Henriques commented
@samerbuna what version of @types/node are you using? I have the same issue and have the all the packages up to date and I'm still seeing that error.
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
Samer Buna commented
@cehenriques @types/node@14
dsehgal-atlassian commented
Anybody seeing this now, updating @types/express
to 4.17.17
resolves this issue for node@16