TypeScript Compiler Options
declaration — TypeScript compiler option
Produces declaration files describing exported and other externally visible type contracts. Declaration files are not implementations; they are used by TypeScript consumers. Declaration generation can surface additional diagnostics. Use an output folder to keep artifacts separate. Default: False normally; implied by composite projects. Create the named files in a clean local project and run tsc -p tsconfig.json. Expected emitted files: dist/example.js, dist/example.d.ts. Run node dist/example.js; expected stdout: '3'. Tested with TypeScript 5.8.3 and Node.js 22.16.0; local project example, not a single-file editor.
Formal Syntax & Structure
typescript syntaxtypescript
{ "compilerOptions": { "declaration": true }}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| declaration | boolean | Set in compilerOptions; False normally; implied by composite projects. |
Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "strict": true, "types": [], "noEmitOnError": true, "outDir": "dist", "declaration": true }, "files": [ "example.ts" ]}// File: example.tsexport const count: number = 3;console.log(count);