TypeScript Compiler Options

rootDirs — TypeScript compiler option

Treats directories as a virtual merged tree for relative module lookup. Useful for generated declaration layers. Does not physically merge folders or rewrite output paths. Default (5.8.3): unset. Create the labeled files in an isolated local project and run tsc -p tsconfig.json. Expected: no diagnostics; emitted files: none. Local multi-file fixture, not a single-file editor.

Formal Syntax & Structure

typescript syntaxtypescript
{  "compilerOptions": {    "rootDirs": [      "src",      "generated"    ]  }}

Parameters & Attributes

NameTypeDescription
rootDirsdirectory path arraySet in compilerOptions; default: unset.

Working Example

Example Snippettypescript
// File: tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [],    "noEmitOnError": true,    "noEmit": true,    "rootDirs": [      "src",      "generated"    ]  },  "files": [    "src/main.ts"  ]}// File: src/main.tsimport { value } from "./generated"; const checked: number = value;// File: generated/generated.d.tsexport declare const value: number;
TypeScript Reference