Sub topic 2
Skipping Declaration File Checks with `skipLibCheck`
Assume you are comfortable with TypeScript generics, union types, tsconfig.json, and running tsc with npm.
Reduce Work with `skipLibCheck`
Declaration files describe types for libraries. They usually end in .d.ts, including files under node_modules/@types. TypeScript must parse these files, but it does not always need to type-check their internal consistency.
Set skipLibCheck to skip type checking for declaration files:
{
"compilerOptions": {
"noEmit": true,
"skipLibCheck": true
},
"include": ["src"]
}Your source files are still checked against the declarations. This option often reduces checking time when dependencies contain many declarations or conflicting library versions.
The trade-off is that errors inside declaration files can remain hidden. Use it when dependency declarations are the bottleneck, not as a replacement for fixing errors in your own .ts files.
Reuse Work with Incremental Builds
An incremental build stores information in a .tsbuildinfo file. Later runs reuse work that did not change.
{
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": ".cache/tsconfig.tsbuildinfo",
"outDir": "dist"
},
"include": ["src"]
}The first run still checks the whole program. Subsequent runs can be much faster when only a few files changed. Do not commit the cache unless your team intentionally shares it. Add its path to .gitignore.
Split Large Codebases with Project References
Project references divide a repository into independently buildable projects. A referenced project normally uses "composite": true, which creates build metadata.
{
"files": [],
"references": [
{ "path": "./packages/core" },
{ "path": "./packages/app" }
]
}Build the dependency graph with:
npx tsc --buildThis works best when package boundaries are stable. It adds configuration and requires explicit dependency order, so do not split a small project without evidence that one program is too large.
Record and Analyze Checker Work
Generate a trace when configuration changes do not explain the slowdown:
npx tsc --noEmit --generateTrace traceDir
npx @typescript/analyze-trace traceDirThe first command records checker activity and type information. The analyzer summarizes expensive operations and points to source locations. Use those locations to simplify deep conditional types, large intersections, or unannotated exported values. Then rerun the same command and compare measurements.
Exercise
What does skipLibCheck skip, and what does it still check?
Show answer
It skips internal type checking of declaration files, but it still checks your TypeScript files against the declarations.