Type Checker Performance

Measuring

In big projects, slow type checking slows the editor and CI. Measure first:

Example

npx tsc --noEmit --extendedDiagnostics

Example output

Files:                         1834
Lines of TypeScript:         210456
Instantiations:             4211873
Memory used:                 812345K
Check time:                   18.42s
Total time:                   24.10s

tsc --generateTrace trace writes a trace you can open in the @typescript/analyze-trace tool or Chrome's performance panel to find the slowest files and types.

Tips

  • Enable "skipLibCheck": true and "incremental": true (stores .tsbuildinfo).
  • Limit global types with "types": [...] and keep include tight (do not type-check dist or generated code).
  • Prefer interface extends over large intersections A & B & C; interfaces are cached.
  • Add explicit return types on exported functions, especially ones returning big inferred types.
  • Avoid huge unions (thousands of members) and deeply recursive conditional types in hot code.
  • Split monorepos with project references; TypeScript 7 (the native Go port, "tsgo") promises about 10x faster checking.