This worked for me!
Using ts-node
Add the following file to add a property to the express Request interface as suggested by @Rishav Sinha
- Add this file
src/types/types.custom.d.ts
declare global {
declare namespace Express {
interface Request {
user?: any,
page?: number,
}
}
}
// If this file has no import/export statements (i.e. is a script)
// convert it into a module by adding an empty export statement.
export { }
- Add in
tsconfig.json
{
"compilerOptions": {
//...
"typeRoots": [
"./types",
"./node_modules/@types"
],
}
// ...
}
- Run this command with
--files
options as suggested by @Shahar Sharron
If you installed globally ts-node
$ ts-node --files ./src/index.ts
or to run from your project dependencies ts-node
$ npx ts-node --files ./src/index.ts
Using nodemon
If you want to use nodemom
- Add this file in folder project
nodemon.json
{
"watch": ["src/**/*.ts"],
"ext": "ts,json",
"ignore": [
"src/**/*.spec.ts",
"src/**/*.test.ts"
],
"exec": "npx ts-node --files ./src/index.ts"
}
- Run
nodemon
$ nodemon
index.d.ts
file on root folder my VScode stopped showing error but I was still getting error on terminal, so I did as you described but directly createdindex.d.ts
file insidecustom_typings
and still it was giving error, it went after creatingexpress
folder, so why is thatexpress
folder mandatory ? – Deranged