Composite project workshop
Concept and boundary
Use project references to express a build graph with a declaration-producing library and dependent application. Build the solution from the root using tsc -b; the application imports the library output contract. A changed upstream type can break the dependent consumer even when the library builds.
Accepted project
Create a fresh folder with exactly these files. Use TypeScript 5.8.3 and Node.js 22.16.0. For the AST explorer only, install the pinned typescript package locally (npm install --save-dev typescript@5.8.3).
import {value} from "../../lib/dist/index"; const n:number=value; console.log(n);app/tsconfig.json
{ "compilerOptions": { "composite": true, "strict": true, "target": "ES2022", "module": "CommonJS", "types": [], "rootDir": "src", "outDir": "dist" }, "include": [ "src" ], "references": [ { "path": "../lib" } ]}lib/tsconfig.json
{ "compilerOptions": { "composite": true, "strict": true, "target": "ES2022", "module": "CommonJS", "types": [], "rootDir": "src", "outDir": "dist" }, "include": [ "src" ]}tsconfig.json
{ "compilerOptions": { "strict": true, "target": "ES2022", "module": "CommonJS", "moduleResolution": "Node10", "moduleDetection": "force", "skipLibCheck": true, "noEmitOnError": true, "types": [] }, "include": [], "exclude": [ "node_modules", "dist", "build", "cache" ], "files": [], "references": [ { "path": "./lib" }, { "path": "./app" } ]}From the project root run: tsc -b tsconfig.json --pretty false.
Compilation succeeds (exit 0).
Run node app/dist/index.js. Expected stdout:
7lib/dist/index.d.ts exists.
Contains "value: number".
app/dist/index.js exists.
Contains "console.log".
Rejected project — diagnosis
Intentionally rejected variant. Do not execute it.
Use a fresh copy of the accepted project, changing only the files shown below.
From the project root run: tsc -b tsconfig.json --pretty false.
Expected compiler diagnostic: TS2322
No runtime execution is required for this check.
The dependent application requires a number but the changed library exports a string. Restore the accepted configuration/source to compare the result.
Practice and recap
Run the build twice, then change only a library implementation body and inspect the next build log.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Composite project workshop — knowledge check
Check the concept, interpret the tested project result, and diagnose a rejected configuration or source.
Which statement correctly describes Composite project workshop?
Using the complete accepted project and the exact command in the lesson, which result is expected?
Why does the rejected project fail under its stated configuration?