TypeScript Compiler Options

outDir — TypeScript compiler option

Redirects emitted artifacts to an output directory, preserving relative structure beneath the effective rootDir. It does not bundle modules, rewrite arbitrary import aliases, or clear stale output. Declaration files can be redirected separately. Default: If omitted, normal per-file JavaScript output is placed beside its source. Create the named files in a clean local project and run tsc -p tsconfig.json. Expected emitted files: dist/main.js, dist/model.js. Run node dist/main.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": {    "outDir": "dist"  }}

Parameters & Attributes

NameTypeDescription
outDirpath stringSet in compilerOptions; If omitted, normal per-file JavaScript output is placed beside its source.

Working Example

Example Snippettypescript
// File: tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [],    "noEmitOnError": true,    "outDir": "dist"  },  "files": [    "src/main.ts",    "src/model.ts"  ]}// File: src/main.tsimport { count } from "./model";console.log(count);// File: src/model.tsexport const count = 3;
TypeScript Reference