helmetjs / helmet

Help secure Express apps with various HTTP headers

Home Page:https://helmetjs.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using helmet for express in a TS project causes a type error

samerbuna opened this issue · comments

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

Sorry you're running into this.

  1. Could you include your tsconfig.json so I can replicate the issue?
  2. Does import helmet = require('helmet') work for you?

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!

@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

@cehenriques @types/node@14

Anybody seeing this now, updating @types/express to 4.17.17 resolves this issue for node@16