Course contentsShow
← TypeScript
Lesson 1222 of 1,79628. tsconfig in DepthFree lesson

Enabling composite: true

Setting composite mode in tsconfig.json and the automatic requirements it enforces like declaration generation.

Enabling composite: true

What you'll learn: How to enable composite mode in your TypeScript project and understand the automatic requirements it enforces.

What Is Composite Mode?

composite: true is a tsconfig.json setting that transforms your project into a building block for TypeScript's project references system. When you enable it, TypeScript enforces strict rules that make your project suitable for being referenced by other projects in a monorepo or multi-project setup.

Think of it like making your project "link-ready" — similar to how a manufacturer must meet certain quality standards before their parts can be used in a larger assembly line.

Enabling Composite

In your tsconfig.json:

{
  "compilerOptions": {
    "composite": true
  }
}

That single line triggers several automatic requirements.

Automatic Requirements Enforced

When you set composite: true, TypeScript automatically enforces:

1. Declaration Files Are Required

The compiler automatically sets declaration: true for you. Your project must generate .d.ts files because other projects will need them to understand your types without reading your source code.

2. RootDir Must Be Explicit or Inferable

TypeScript needs to know exactly where your source files live. Either set rootDir explicitly or ensure TypeScript can infer it from your include patterns.

3. All Implementation Files Must Be Matched

Every .ts file must either be included in compilation or explicitly excluded. No orphaned files allowed — this ensures complete, predictable builds.

Why These Requirements?

Composite projects are designed to work efficiently with project references. The declaration files let dependent projects check types without recompiling your source. The strict file matching ensures reproducible builds across different machines.

Key Takeaway: Enabling composite: true turns your project into a reusable, type-safe building block by automatically requiring declaration generation and enforcing strict file inclusion rules — essential for multi-project TypeScript setups.