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.
tsconfig.json
here? – Cory@types/express-serve-static-core
package? If so, you aren't doing that properly. – Chainsmokesrc/types/index.d.ts
first. If you really wanted to you could confirm that by setting a breakpointsrc/types/index.d.ts
and another in your file wherereq.customFlag
is used, and checking which gets triggered first in each configuration. – VolumeterskipLibCheck
options set totrue
? – Licha