Success story!
Utilizing ts-node
To enhance the express Request interface, follow the advice of @Rishav Sinha by adding this file:
- Add the file
src/types/types.custom.d.ts
declare global {
declare namespace Express {
interface Request {
user?: any,
page?: number,
}
}
}
// If there are no import/export statements in this file (i.e. it's a script)
// convert it into a module by including an empty export statement.
export { }
- Include in
tsconfig.json
{
"compilerOptions": {
//...
"typeRoots": [
"./types",
"./node_modules/@types"
],
}
// ...
}
- Execute this command with the
--files
options as recommended by @Shahar Sharron
If you have globally installed ts-node
$ ts-node --files ./src/index.ts
or if running from your project dependencies, use ts-node
$ npx ts-node --files ./src/index.ts
Employing nodemon
For those interested in using nodemom
- Add this file to your project folder
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