I have been making a webpage for the past two days and I have chosen to use TypeScript.
I have chosen Express.js as the web server, and I have used Express in the past so I know about Express.
I saw that TypeScript looks highly at each property and what properties have, and I have a problem with this because the property "user" is not set by default and I want to use it to save the decoded user session.
After searching online, I found this:
declare module "express" { // declare module "express-serve-static-core"
export interface Request {
user: any
}
}
from this post: Typescript Error: Property 'user' does not exist on type 'Request'
I pasted that into a file and it works well but I have two problems:
- I don't know why it works. I don't require the file but however this works, the unique that I made is to require it this in typeroots inside tsconfig.json but executing with ts-node. I don't know if it has any effect (in fact, Visual Studio Code does not throw an error but ts-node does).
- I want to give user the type Session, so I imported Session into the file, but now Visual Studio Code tells me that is not in the User property.