I write my project code in VSCode, I have been writing Node.js Express application. I need to access req.user.name from Request object, VSCode complained that name does not exist in user object. So I created global.d.ts file in my project root directory which has the following content:
declare namespace Express {
interface User {
userName: string;
name: string;
email: string;
}
}
In my tsconfig.json, I have referenced this file as follows:
{
"compilerOptions": {
"typeRoots": ["./node_modules/@types", "./global.d.ts"]
},
"include": [/*...*/,"global.d.ts"]
}
After this, VSCode stopped complaining me about the error above, but when I try to compile the project with actual tsc, it throws error.
Error from the compiler: error TS2339: Property 'name' does not exist on type 'User'.
For some reason, VSCode and TS compiler are not in sync.
How can I resolve this?