Master tsconfig project references, incremental compilation, and composite builds for high-performance monorepo architectures.
Discover how TypeScript infers types automatically and how let versus const declarations shape wide types versus narrow literal types.
In large enterprise codebases and monorepos, compiling all source files as a single monolithic program slows down build times. Project References allow you to structure TypeScript code into independent, interlinked modules.
To allow a project to be referenced by another tsconfig.json, enable "composite": true in the child project's configuration:
// packages/core/tsconfig.json
{
"compilerOptions": {
"composite": true,
"declaration": true,
"rootDir": "src",
"outDir": "dist"
}
}
Reference child projects in the root or consuming app tsconfig.json:
// apps/web/tsconfig.json
{
"compilerOptions": {
"target": "ES2022"
},
"references": [
{ "path": "../../packages/core" }
]
}
tsc -b)Use TypeScript's build mode (tsc -b) to compile referenced projects incrementally:
# Build referenced projects incrementally in correct dependency order!
tsc -b apps/web
.d.ts outputs have not changed.declaration: true to generate build declaration maps for consumer projects.Congratulations! You have completed all 30 foundational TypeScript Learning Bytes, mastering everything from primitive type annotations to generics, conditional types, custom utility types, and enterprise monorepo compilation!