Advertisement
Intermediate TypeScript, tsconfig & Compiler Options

What is the difference between the 'include'/'exclude' arrays and the 'files' array in tsconfig.json for specifying which files are part of the compilation?

Short answer

'include' specifies glob patterns for files/directories to bring INTO the project (with 'exclude' subtracting specific patterns back out, commonly node_modules by default); 'files' instead lists an EXPLICIT, exhaustive array of individual file paths — useful for very small…

Save TypeScript mock interview
Advertisement
AModel answer
'include' specifies glob patterns for files/directories to bring INTO the project (with 'exclude' subtracting specific patterns back out, commonly node_modules by default); 'files' instead lists an EXPLICIT, exhaustive array of individual file paths — useful for very small projects, but impractical to maintain manually as a project grows.
{
  "include": ["src/**/*.ts"],
  "exclude": ["src/**/*.test.ts", "node_modules"]
}
// vs.
{
  "files": ["src/index.ts", "src/utils.ts"] // must list every file explicitly
}
Real-world example
Excluding test files or generated code from the main application's production TypeScript compilation.
Likely follow-ups
  • What is included by default if NEITHER 'include' nor 'files' is specified at all?
Related topics