TypeScript Compiler Options
references — TypeScript project configuration
Declares project dependencies by paths to directories or config files. Use a solution config with files: [] to avoid compiling the same sources twice. Dependencies build first in build mode, not necessarily in array order. References do not create a package alias and are not inherited via extends. Baseline: TypeScript 5.8.3. Default: none. Example: create the labeled files in an isolated project and run the commands in order. See companion fixtures for comparison cases and expected results. Both projects build; running the app prints 8.
Formal Syntax & Structure
typescript syntaxtypescript
{ "references": [ { "path": "./lib" } ]}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| references | array of { path: string } | Top-level TSConfig property; default: none. |
Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "files": [], "references": [ { "path": "./app" }, { "path": "./lib" } ]}// File: lib/tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "strict": true, "types": [], "composite": true, "rootDir": "src", "outDir": "dist", "tsBuildInfoFile": "dist/lib.tsbuildinfo" }, "include": [ "src/**/*.ts" ]}// File: lib/src/index.ts (omit this label)export const value: number = 7;// File: app/tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "strict": true, "types": [], "composite": true, "rootDir": "src", "outDir": "dist", "tsBuildInfoFile": "dist/app.tsbuildinfo" }, "include": [ "src/**/*.ts" ], "references": [ { "path": "../lib" } ]}// File: app/src/index.ts (omit this label)import { value } from "../../lib/dist/index";console.log(value + 1);
// Run these commands in order in an isolated project:// tsc --build --pretty false// node app/dist/index.js