I have the following piece of code in my express app
router.get('/auth/userInfo', this.validateUser, (req, res) => {
res.json(req.user);
});
and my IDE seems to be complaining with the error
error TS2339: Property 'user' does not exist on type 'Request'.
When I compile my typescript code it seems to be throwing this error. Any ideas why this is happening?
Best Answer
We have a large API written in Express and Typescript, and this is how we handle such scenarios:
We keep the request definitions in one file:
And then in the file where we are writing the controller functions:
Be advised that "user" is not a property that is available natively in the Request object of Express. Make sure that you are using a middleware that adds such property to the request object.