patterntypescriptnoneTip
TypeScript Incremental Builds with tsBuildInfoFile
Viewed 0 times
TypeScript 3.4+
incrementaltsBuildInfoFilebuild cachecompile speedtscperformance
Error Messages
Problem
TypeScript recompiles the entire project on every tsc invocation even when only one file changed, making build times grow linearly with project size.
Solution
Enable 'incremental: true' to cache build information and skip unchanged files.
// tsconfig.json
{
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./.tsbuildinfo"
}
}# First build: full compile, creates .tsbuildinfo
tsc
# Second build: only changed files recompiled
tsc # Much faster
# In .gitignore
echo ".tsbuildinfo" >> .gitignore
# For --noEmit with incremental:
tsc --noEmit --incremental --tsBuildInfoFile .tsbuildinfo// package.json
{
"scripts": {
"typecheck": "tsc --noEmit --incremental --tsBuildInfoFile .tsbuildinfo",
"build": "tsc --build"
}
}Why
The .tsbuildinfo file stores a fingerprint of each file's content and its resolved types. On subsequent builds, TypeScript skips files whose fingerprints match, only recompiling changed files and their dependents.
Gotchas
- The .tsbuildinfo file must not be committed to source control — it is machine-specific.
- Delete .tsbuildinfo when tsconfig changes significantly to avoid stale cache.
- Incremental with --noEmit requires explicitly specifying --tsBuildInfoFile — otherwise TypeScript errors.
Revisions (0)
No revisions yet.