← Back to TypeScript Course | Chapter 17: TypeScript Configuration | Lesson 6 of 7

Composite Projects

A composite project is configured with composite: true so TypeScript can use it as part of a project reference graph. Composite projects have stricter configuration requirements and produce build information that helps TypeScript manage dependencies.

Enabling composite

Set composite to true in a project's compilerOptions when that project is meant to be referenced by another project — it's the flag that unlocks project-reference behavior for that specific tsconfig.json.

Example: Enabling composite

typescript
// tsconfig.json
// { "compilerOptions": { "composite": true } }
console.log("composite: true unlocks project-reference behavior for this config");

Composite and Declaration Files

Composite projects generally need declaration output turned on so dependent projects can see and type-check against their public types without needing access to the original source files.

Example: Composite and Declaration Files

typescript
// tsconfig.json
// { "compilerOptions": { "composite": true, "declaration": true } }
console.log("Composite projects need declaration output for dependents to use");

Composite and rootDir

A composite project has stricter source-file requirements than a normal project, so defining a clear rootDir keeps its output structure predictable for whatever project ends up referencing it.

Example: Composite and rootDir

typescript
// tsconfig.json
// { "compilerOptions": { "composite": true, "rootDir": "src" } }
console.log("A clear rootDir keeps composite project output structure predictable");

Composite with References

Composite projects are the building blocks of a project-reference graph — each one is a self-contained unit that other projects can point at via the references array in their own tsconfig.json.

Example: Composite with References

typescript
// consumer/tsconfig.json
// { "references": [{ "path": "../composite-lib" }] }
console.log("Composite projects are the buildable units other projects reference");

Incremental Builds

Composite projects work naturally with TypeScript's incremental build information, letting tsc -b skip rebuilding projects whose source hasn't changed since the previous build, which speeds up large monorepos significantly.

Example: Incremental Builds

typescript
// tsc -b   (skips projects whose source hasn't changed)
console.log("Composite projects enable fast incremental builds in monorepos");
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.