TypeScript Declaration Files

Triple-slash reference path

A leading triple-slash path directive adds a referenced file to the compiler program. The path is relative to the containing file. It is not a runtime import; prefer ordinary module imports when describing module dependencies. The fixture explicitly lists only main.ts. Baseline: TypeScript 5.8.3. File labels are explanatory; create the files separately.

Formal Syntax & Structure

typescript syntaxtypescript
/// <reference path="./contract.d.ts" />

Working Example

Example Snippettypescript
// File: tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [],    "noEmit": true,    "skipLibCheck": false,    "lib": [      "ES5"    ]  },  "files": [    "main.ts"  ]}
// File: contract.d.ts (omit this label)interface Ticket { id: number }
// File: main.ts (omit this label)/// <reference path="./contract.d.ts" />const ticket: Ticket = { id: 1 };
// Run: tsc -p . --pretty false// Expected: no diagnostics.
TypeScript Reference