TypeScript Compiler Options
declarationDir — TypeScript compiler option
Redirects generated declaration files and declaration maps to a separate directory. JavaScript still follows outDir or normal emission rules. Requires declaration generation; consumers must point to the actual packaged type entry point. Default: If omitted, declaration output follows normal output placement. Create the named files in a clean local project and run tsc -p tsconfig.json. Expected emitted files: dist/example.js, types/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": { "declarationDir": "types" }}Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| declarationDir | path string | Set in compilerOptions; If omitted, declaration output follows normal output placement. |
Working Example
Example Snippettypescript
// File: tsconfig.json (omit this label){ "compilerOptions": { "target": "ES2022", "module": "CommonJS", "strict": true, "types": [], "noEmitOnError": true, "outDir": "dist", "declaration": true, "declarationDir": "types" }, "files": [ "example.ts" ]}// File: example.tsexport const count: number = 3;console.log(count);