In my TypeScript project I'm extending express Request type to add own properties. I have a file src/types/index.d.ts that looks similar to this:
declare module 'express-serve-static-core' {
interface Request {
customFlag?: boolean;
}
}
Part of my tsconfig.json looks like this:
"include": [
"src/**/*.ts",
"./server.ts"
],
When I'm runnning the project, it crashes on req.customFlag usage (says that property does not exist for type).
If I modify my tsconfig.json as follows:
"include": [
"src/**/*.ts",
"./server.ts"
],
"files": [
"src/types/index.d.ts"
],
it starts to work smoothly.
Why is that? My understanding of TS docs is that include and files are interpreted the same way, the only difference is that the first allows to specify patterns.
If I run tsc --listFiles --noEmit, the result contains src/types/index.d.ts for both configs. Yet for the first one it's not working.