TypeScript Compiler Options

baseUrl — TypeScript compiler option

Provides a base directory for non-relative specifiers; relative imports are unaffected. Not required for paths in modern TypeScript. Does not configure runtime loaders and may shadow package names. 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": {    "baseUrl": "./src"  }}

Parameters & Attributes

NameTypeDescription
baseUrldirectory pathSet 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,    "baseUrl": "./src"  },  "files": [    "main.ts"  ]}// File: main.tsimport { value } from "util-local"; console.log(value);// File: src/util-local.tsexport const value = 7;
TypeScript Reference