TypeScript Compiler Options

typeRoots — TypeScript compiler option

Restricts directories for automatic type-package inclusion. Each directory should contain package subdirectories. Explicit types further restricts inclusion. Does not install runtime globals. Default (5.8.3): visible ancestor node_modules/@types directories. 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": {    "typeRoots": [      "./typings"    ]  }}

Parameters & Attributes

NameTypeDescription
typeRootsdirectory path arraySet in compilerOptions; default: visible ancestor node_modules/@types directories.

Working Example

Example Snippettypescript
// File: tsconfig.json (omit this label){  "compilerOptions": {    "target": "ES2022",    "module": "CommonJS",    "strict": true,    "types": [      "local"    ],    "noEmitOnError": true,    "noEmit": true,    "typeRoots": [      "./typings"    ]  },  "files": [    "main.ts"  ]}// File: main.tsconst checked: number = LOCAL_COUNT;// File: typings/local/index.d.tsdeclare const LOCAL_COUNT: number;
TypeScript Reference