TypeScript Declaration Files
Triple-slash reference types
A leading triple-slash types directive explicitly requests a declaration package. This controlled project disables automatic @types inclusion with types: [] and includes the synthetic demo package only through the directive. It supplies declarations, not runtime code. Baseline: TypeScript 5.8.3. File labels are explanatory; create the files separately.
Formal Syntax & Structure
typescript syntaxtypescript
/// <reference types="package-name" />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: node_modules/@types/demo/index.d.ts (omit this label)interface DemoTicket { id: number }
// File: main.ts (omit this label)/// <reference types="demo" />const ticket: DemoTicket = { id: 2 };
// Run: tsc -p . --pretty false// Expected: no diagnostics.