Incremental Builds in CI with --incremental
What you'll learn: How to use TypeScript's --incremental flag with .tsbuildinfo files to dramatically speed up repeated type-checks in continuous integration pipelines.
The Problem with CI Type-Checks
Every time your CI pipeline runs tsc --noEmit to type-check your code, TypeScript analyzes every single file from scratch—even if you only changed one line in one file. For large codebases, this can take minutes, slowing down your feedback loop and wasting CI resources.
How Incremental Compilation Works
When you enable --incremental, TypeScript creates a .tsbuildinfo file that stores information about the previous compilation: which files were checked, their signatures, and dependency relationships. On subsequent runs, TypeScript can skip files that haven't changed and only re-check what's necessary.
Think of it like this: Without incremental builds, CI is like recounting every vote in every district for every election. With incremental builds, you only recount districts where something changed.
Enabling Incremental Builds in CI
Add --incremental to your type-check command:
tsc --noEmit --incremental
Or set it in tsconfig.json:
{
"compilerOptions": {
"incremental": true
}
}
The Critical CI Step: Cache the .tsbuildinfo
For incremental builds to work across CI runs, you must cache the .tsbuildinfo file between pipeline executions. In GitHub Actions, this means caching it alongside node_modules. Without caching, each CI run starts fresh and gains nothing from --incremental.
Key Takeaway: Use --incremental with .tsbuildinfo caching in CI to skip unchanged files and cut type-check times dramatically—sometimes from minutes to seconds on subsequent runs.