TypeScript Declaration Files
Global declaration file
A declaration file without a top-level import or export can introduce global type names to an including program. Adding export {} makes the file a module and prevents its ordinary declarations from leaking globally. This example declares only a type, not a runtime global. Baseline: TypeScript 5.8.3. File labels are explanatory; create the files separately.
Formal Syntax & Structure
typescript syntaxtypescript
interface Name { property: Type }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: globals.d.ts (omit this label)interface BuildInfo { version: string }
// File: main.ts (omit this label)/// <reference path="./globals.d.ts" />const info: BuildInfo = { version: "dev" };
// Run: tsc -p . --pretty false// Expected: no diagnostics.