Within our web app that utilizes TypeScript and express, we integrated the npm package express-request-id to enhance our HTTP Requests and responses by adding X-Request-Id headers.
We crafted a middleware to assign the request's id
to the HTTP response header in the following manner:
import type { Request, NextFunction, RequestHandler, Response } from 'express'
//...
export const requestIdHandler = (_fn: RequestHandler) => (req: Request, res: Response, _next: NextFunction) => {
res.set('X-Request-Id', req.id)
}
Expectedly, this does not integrate seamlessly due to the fact that the id
property is lacking in the express-defined type. Upon discovery, we observed that the types.d.ts file in express-request-id supersedes the type definition of the Request
type established by express, yet we encountered difficulties importing that type. What would be the proper approach to import the overridden type?