Menu

Project References, Monorepos, and Build Speed

Lesson 4: Project References, Monorepos, and Build Speed

How do large projects stay fast?

Technique What it does
Project references Split a codebase into smaller projects that build in order
composite: true Marks a project as referenceable and enables incremental builds
tsc --build (-b) Builds referenced projects, skipping unchanged ones
incremental: true Saves build info to reuse on the next run
skipLibCheck: true Skips type-checking dependencies' declaration files
Explicit types Loads only the @types packages you need
TypeScript 7 native compiler Checks code in parallel, often about 10× faster than 6.0

Example: monorepo layout

quickcart/
├─ packages/
│  ├─ shared/      # Types and utilities
│  │  └─ tsconfig.json
│  ├─ api/         # Node.js service
│  │  └─ tsconfig.json
│  └─ web/         # React app
│     └─ tsconfig.json
└─ tsconfig.json   # Solution file
// packages/shared/tsconfig.json
{
  "compilerOptions": { "composite": true, "outDir": "dist", "declaration": true },
  "include": ["src"]
}
// packages/api/tsconfig.json
{
  "compilerOptions": { "outDir": "dist" },
  "references": [{ "path": "../shared" }],
  "include": ["src"]
}
// tsconfig.json (root)
{
  "files": [],
  "references": [{ "path": "packages/shared" }, { "path": "packages/api" }, { "path": "packages/web" }]
}
npx tsc --build          # Build everything in dependency order
npx tsc --build --watch  # Rebuild only what changed

How it works

  • shared builds first and emits .d.ts files; api and web read those instead of re-checking shared's source.
  • Editors also load only the projects you open, which keeps them responsive.
  • TypeScript 7 adds flags to tune parallelism: --checkers and --builders, plus --singleThreaded for limited environments such as small CI machines.
  • TypeScript 7.0 does not include the programmatic compiler API; TypeScript 7.1 brings a new one. Tools that still need the old API can run alongside the @typescript/typescript6 compatibility package.

Common mistakes

Mistake Effect Fix
Referencing a project without composite: true Error Add composite to referenced projects
Importing another package's source files directly Slow builds, duplicate checking Import through the package name and references
Running plain tsc instead of tsc -b in a references setup Projects build in the wrong order Use --build

Key takeaways

  • Project references split large codebases into fast, incremental builds.
  • TypeScript 7's native compiler makes large-scale checking much faster with no code changes.

Try it: Split QuickCart into shared and api projects with references, then run tsc --build twice and compare the times.


TypeScript Tutorial

J

Jebasta





Get in Touch For Details