Skip to content
Tutorials Center
My learning

Topics

TypeScript Reference ยท tsconfig: Projects, Files and Watch Options

TypeScript explainFiles option

Reference for the TypeScript explainFiles option: list each file in the program with the reason it was included, to debug slow or oversized builds.

explainFiles prints every file in the program together with the reason or reasons it was included. Typical reasons: the file matched an include pattern, it is a root file named on the command line, another file imported it, or a library or type reference pulled it in.

It is the tool to reach for when a build includes files you did not expect, such as test files in production output or thousands of declaration files from node_modules/@types. It does not change the program.

TEXT
tsc --noEmit --explainFiles

Try it

Real output contains your absolute paths, so these examples model the reasons as data.

TypeScript Reasons as a union type

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

TypeScript Finding unexpected inputs

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or readFileSync(0)), it gets the next line from this box.

Syntax

JSON
{ "compilerOptions": { "explainFiles": true } }
TEXT
tsc --explainFiles

Output shape: a file path line followed by indented reason lines. Common reason texts include "Root file specified for compilation", "Matched by include pattern '...' in 'tsconfig.json'", "Imported via '...' from file '...'", "Library '...' referenced via 'lib' from file ...", and "Entry point for implicit type library '...'".

Usage notes

  • Pair with --noEmit to inspect without writing files.
  • Unexpected @types packages show an "implicit type library" reason; restrict them with the types option.
  • A reason chain, not a cause. A file imported by an imported file lists only its direct importer.
  • Broad include patterns such as **/* are the most common source of surprise; narrow them or add exclude.
  • Combine with listFiles when you only need the plain list, and with traceResolution when the question is how an import was resolved.
  • Output is long. Redirect it to a file and search.