TypeScript Declaration Files
Triple-slash no-default-lib directive
This directive marks a file as a default library and suppresses automatic default library inclusion in a program containing it. It is chiefly intended for library declaration authors. Explicitly referenced libraries can still be included; this fixture requests ES5 and demonstrates the absence of the DOM global document. Prefer project-level lib configuration for applications. Baseline: TypeScript 5.8.3. File labels are explanatory; create the files separately.
Formal Syntax & Structure
typescript syntaxtypescript
/// <reference no-default-lib="true" />Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "strict": true, "types": [], "noEmit": true, "skipLibCheck": false }, "files": [ "main.ts" ]}
// File: main.ts (omit this label)/// <reference no-default-lib="true" />/// <reference lib="es5" />const size: number = "abc".length;
// Run: tsc -p . --pretty false// Expected: no diagnostics.