Please help, I am getting this error
src/app/middlewares/authentication.ts:16:17 - error TS2339: Property 'user' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
16 req.user = user;
I have created the .d.ts file and also included it in tsconfig file. Still I am not able to run this code
Please find attached screenshots
src/
- types/
- express/
- index.d.ts
import express from "express";
declare global {
namespace Express {
interface Request {
user?: Record<string,any>
}
}
}
{
"compilerOptions": {
"typeRoots" : ["./src/types", "./node_modules/@types"]
}
}
This should work
I was stuck on the same problem earlier. Here is how I solved it.
import * as express from "express"
declare global {
namespace Express {
interface Request {
user? : Record<string,any>
}
}
}
"compilerOptions": {
...other settings,
"typeRoots": ["@types", "node_modules/@types"],
...other settings
}
And that's it. It should works with these changes.