I tried to modify the express request inmiddleware.While I type the code there is no error and it shows signature of the request.user but while compiling it throwing error
middleware.ts
const myMiddleware = (req: Request, res: Response, next: NextFunction): void => {
req.user = {
userId: 1,
}
next()
}
src/@types/express/index.d.ts
declare namespace Express {
export interface Request {
user: any
}
}
tsconfig.json
"typeRoots": ["src/@types", "node_modules/@types"],
error
error TS2339: Property 'user' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
44 req.user = {
What is missing here or Do I need to updated the code ?
How to resolve this or any alternative solution,I do have multiple middlewares.