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

Project References

Project references let a large TypeScript codebase be divided into smaller TypeScript projects. Each referenced project can have its own tsconfig.json and build output, improving organization and incremental builds.

Basic Project Reference

The references property points from one TypeScript project's config to another project's config, letting a large codebase be split into smaller, independently-buildable pieces that still type-check against each other.

Example: Basic Project Reference

typescript
// app/tsconfig.json
// { "references": [{ "path": "../shared" }] }
console.log("references points from one project's config to another's");

Referenced Project Configuration

A referenced project needs a compatible configuration, most importantly composite: true, so the TypeScript compiler can generate the declaration output that other projects referencing it will depend on.

Example: Referenced Project Configuration

typescript
// shared/tsconfig.json
// { "compilerOptions": { "composite": true, "declaration": true } }
console.log("composite: true lets other projects depend on this one's output");

Application and Library Projects

A common structure separates reusable library code into its own referenced project from the application that consumes it, so the library can be built, tested, and versioned somewhat independently.

Example: Application and Library Projects

typescript
// packages/lib/tsconfig.json    (composite: true)
// packages/app/tsconfig.json    references: [{ path: "../lib" }]
console.log("Library and app split into separately buildable projects");

Building Referenced Projects

TypeScript's build mode (tsc -b) understands project references and builds referenced projects in the correct dependency order automatically, skipping projects that haven't changed since the last build.

Example: Building Referenced Projects

typescript
// tsc -b
console.log("tsc -b builds referenced projects in correct dependency order");

Benefits of Project References

Project references pay off on large codebases by separating concerns, reducing unnecessary recompilation, and making the dependency graph between packages explicit instead of implicit through shared node_modules.

Example: Benefits of Project References

typescript
// Faster incremental builds, clear dependency graph, separated concerns.
console.log("Project references scale TypeScript to large, multi-package codebases");
🔒

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.