Lesson 1 of 9 · 28m
Project References and Composite Builds That Actually Scale
Learn when TypeScript project references pay for themselves, how composite constraints change your code, and how to avoid reference graph chaos.
The first time most teams meet project references, they copy a monorepo blog post, split twenty packages, and discover that every package now has its own opinion about tsconfig.json. Build times get worse. Editors get confused. Someone adds ts-node back into production because it feels easier. Project references are not a folder-organizing feature. They are a build graph with explicit contracts.
The mental model: compilation units, not packages
A project reference tells TypeScript: "this unit depends on the declarations produced by that unit." The referenced project must normally use composite: true, which makes its output stable enough for downstream type-checking:
{
"compilerOptions": {"composite": true, "declaration": true, "declarationMap": true, "rootDir": "src", "outDir": "dist"},
"include": ["src"]
}{
"references": [{"path": "../core"}],
"compilerOptions": {
"composite": true,
"outDir": "dist"
}
}Run the graph with build mode, not plain tsc:
tsc --build tsconfig.json --verbose
tsc --build tsconfig.json --cleanBuild mode checks timestamps and .tsbuildinfo state. It is the difference between compiling the repository and compiling the part of the repository that changed.
Composite has teeth
composite is not a ceremonial flag. It implies declaration emit and forces a clearer boundary between input and output. Files cannot casually wander outside rootDir, and implementation details that leak into public types become expensive. That is a feature. A referenced project's .d.ts files are its API surface, whether or not anyone designed them.
New hires usually expect references to enforce runtime module boundaries too. They do not. TypeScript's build graph does not bundle your application, and it does not stop a package from importing ../../core/src/internal/database if path resolution allows it. Pair references with package boundaries and lint rules.
Shape the graph like dependencies, not folders
Good reference graphs are shallow and directional:
app -> features -> domain -> core
app -> platform -> core
tests -> fixtures -> domainBad graphs mirror whatever directory layout happened to exist. Cycles, diamonds with conflicting settings, and leaf packages that know about applications are all signals that ownership is wrong. If two projects need each other, usually the shared abstraction belongs below both.
Field notes
tsc --buildis incremental across projects; plaintsc -pis not the same workflow.- Do not commit
distmerely to make references work. Commit generated contracts only when the repository intentionally versions build artifacts. disableSourceOfProjectReferenceRedirectcan make editors use declarations instead of source; useful sometimes, confusing by default.- Project references multiply configuration mistakes. Generate shared config from a base file and keep per-project overrides small.
- If a package is never compiled independently, a project reference may be ceremony rather than architecture.
Was this lesson helpful?