1
I want to add a property user for the Express request. For this I created a file called express.d.ts with the following content:
declare namespace Express {
export interface Request {
user: {
id: string;
}
}
}
While trying to access in my middleware the property request user. created, I have the following mistake:
- error TS2339: Property 'user' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs>'.
Middleware class code class name.ts:
export default function methodName(request: Request, response: Response, next: NextFunction): void{
request.user = {
id: 10,
}
}
Folder structure:
src
@types
express.d.ts
middlewares
className.ts