I am working on an express app and I wanted to add a new property on Request's class instance.
So I created a type.d.ts file at my project root similar to
type User = {
name: string
}
declare namespace Express {
export interface Request {
user: User
}
}
Then somewhere in my middleware function,
const user = req.user.name
The above code throws error saying,
Property user does on exist on type Request<ParamsDictionary, any, any .....>
However, VS code does not complains anything about it, only when I try to start the express server using nodemon then it throws an error.
Any clue on this would be helpful. Thanks in advance.