Skip to content

Support Express 5 types #1437

Open
Open
@rabidpraxis

Description

@rabidpraxis

Currently our recommended installation is failing type checks for typescript projects including express > 5.0.

error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type '(req: Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>, res: Response<any, Record<string, any>>, next: NextFunction) => void' is not assignable to parameter of type 'PathParams'.

12 app.use(Honeybadger.requestHandler);
           ~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/@types/express-serve-static-core/index.d.ts:157:5
    157     <
            ~
    158         P = ParamsDictionary,
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ...
    166         ...handlers: Array<RequestHandlerParams<P, ResBody, ReqBody, ReqQuery, LocalsObj>>
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    167     ): T;
        ~~~~~~~~~
    The last overload is declared here.

A workaround is to ignore the type errors with something like this:

app.use(Honeybadger.requestHandler as unknown as express.RequestHandler);

We should update the type definitions for Honeybadger.requestHandler and errorHandler to be compatible with Express 5’s middleware types, so TypeScript projects do not require unsafe type casts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions