Sub topic 8
How `.tsbuildinfo` Enables Incremental Builds
Assume you know basic TypeScript, tsconfig.json, project references, and how to run tsc. This chapter focuses on what happens after a referenced project has been built once.
What `.tsbuildinfo` stores
A .tsbuildinfo file is TypeScript's record of a previous build. It stores information such as:
- Which source files belong to the project.
- Compiler options used for the build.
- The relationships between imported files.
- The output files produced for each source file.
- A version for each file's contents.
- A public signature for each declaration output.
The file is build metadata. It is not JavaScript, a declaration file, or an artifact that your application loads at runtime.
When you use a composite project, TypeScript enables the information needed for incremental project builds. The compiler normally writes the metadata beside the project's output, often under outDir. For example, a project with outDir: "dist" may produce dist/tsconfig.tsbuildinfo.
How incremental checking works
On the first build, TypeScript checks every required file and writes the project's outputs and build information. On a later build, TypeScript compares the current project with that record.
If a source file has not changed, TypeScript can reuse its previous result. If a file changed, TypeScript checks that file and follows its dependencies. It also examines the generated declaration signature to decide whether dependent projects need new type-checking.
A change to an implementation may leave the public signature unchanged:
export function greet(name: string): string {
return `Welcome, ${name}.`;
}A dependent project usually does not need to be type-checked again when only the function body changes. A change to the signature does affect dependents:
export function greet(name: string, punctuation = "!"): string {
return `Welcome, ${name}${punctuation}`;
}The exact work still depends on compiler options and the files involved, but declaration signatures provide the important boundary between projects.
Inspecting and controlling the metadata
Use verbose or dry-run output to see why TypeScript considers a project out of date:
tsc --build --dry --verboseThis command does not write outputs. It reports which projects would build and which dependency or file change caused that decision.
Use normal build mode to reuse available metadata:
tsc --buildUse --force when you need every project rebuilt even if the outputs appear current:
tsc --build --forceUse --clean to remove outputs and build information for the projects in the build graph:
tsc --build --cleanA clean build is useful for testing reproducibility or recovering from stale generated files. Do not commit to a build strategy that depends on old metadata being present. A missing .tsbuildinfo file is safe: TypeScript performs a full build and creates it again.
CI and watch mode
Local development benefits most from incremental metadata because repeated builds can skip unchanged work. In CI, a clean checkout commonly has no .tsbuildinfo, so the first build is full. Later jobs can reuse metadata only if the CI system deliberately restores a compatible cache.
Watch mode keeps the same dependency information updated as files change:
tsc --build --watchIf incremental behavior looks wrong, inspect the verbose build output, verify that generated directories are not being mixed with source directories, and run a forced or clean build to separate stale metadata from a real configuration problem.
Exercise
A change modifies only the body of a function in core, while its emitted declaration signature stays the same. Should a referenced app project normally need a full type-check?
Show answer
No. TypeScript can rebuild core while reusing app's previous type information because core's public declaration signature did not change.