content

Extend Express request object using Typescript

Here is how to type a request of type Express, you have to declare a namespace and an interface to add additional parameters to the initial request.


// custom.d.ts
declare namespace Express {
  export interface Request {
    custom? : string
  }
}


// Route
router.use((req, res, next) => {
  req.custom = "content";
  next()
})