As a novice in typescript, I find myself delving into express and typescript and encountering the need to access req.id
within a middleware function.
Unfortunately, attempting to do so results in this error message:
Property 'id' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs>'
This is the code snippet I am currently using:
app.use(function (req, res, next) {
var log = logger.child(
{
id: req.id,
body: req.body,
params: req.params,
},
true
);
log.info({ req: req });
next();
});
For now, I have been resorting to suppressing typescript errors with //@ts-ignore
comments.
Additionally, I would appreciate any guidance on how to extend types in modules/packages to combat similar issues that may arise in the future.