Advertisement
Advanced TypeScript, tsconfig & Compiler Options

How do TypeScript project references ('references' + 'composite': true) improve build performance and enforce boundaries in a large monorepo?

Short answer

Project references let you split a large codebase into independently-buildable sub-projects with explicit declared dependencies between them; TypeScript then performs INCREMENTAL builds (via 'tsc --build'), only recompiling projects whose dependencies actually changed, and…

Save TypeScript mock interview
Advertisement
AModel answer
Project references let you split a large codebase into independently-buildable sub-projects with explicit declared dependencies between them; TypeScript then performs INCREMENTAL builds (via 'tsc --build'), only recompiling projects whose dependencies actually changed, and enforces that a project can only import from packages it explicitly references — catching accidental circular or unauthorized cross-package imports at the project-structure level.
// packages/shared/tsconfig.json
{ "compilerOptions": { "composite": true }, "include": ["src"] }

// packages/app/tsconfig.json
{
  "compilerOptions": { "composite": true },
  "references": [{ "path": "../shared" }]
}
// Build with: tsc --build packages/app
Real-world example
Structuring a large monorepo so changing one package doesn't force a full, slow rebuild of every unrelated package.
Likely follow-ups
  • What must 'composite': true additionally require regarding the 'declaration' compiler option?
Related topics