tsconfig.json Deep Dive
In this page:
Basic tsconfig.json
A basic tsconfig.json can specify the ECMAScript target, module system, source directory, and output directory — these four settings alone are usually enough to get a small project compiling correctly.
Example: Basic tsconfig.json
// tsconfig.json
// { "compilerOptions": { "target": "ES2020", "module": "commonjs", "rootDir": "src", "outDir": "dist" } }
console.log("target, module, rootDir, outDir are usually enough to start");
include and exclude
The include and exclude properties control which files TypeScript actually treats as part of the project, which matters for both compile speed and avoiding accidental type-checking of test fixtures or generated output.
Example: include and exclude
// tsconfig.json
// { "include": ["src/**/*"], "exclude": ["node_modules", "**/*.test.ts"] }
console.log("include/exclude control which files TypeScript actually checks");
Compiler Options
compilerOptions holds the main settings that control TypeScript's type checking and JavaScript generation, from strictness flags to target syntax — it's the section you'll touch most often as a project's needs evolve.
Example: Compiler Options
// tsconfig.json
// { "compilerOptions": { "strict": true, "target": "ES2022" } }
console.log("compilerOptions holds most of the settings you'll actually touch");
Source Maps and Declarations
Options such as sourceMap and declaration generate extra output files useful for debugging (mapping compiled JS back to original TS) and for library development (shipping .d.ts files alongside the compiled code).
Example: Source Maps and Declarations
// tsconfig.json
// { "compilerOptions": { "sourceMap": true, "declaration": true } }
console.log("sourceMap aids debugging, declaration ships .d.ts files");
Extending Configuration
A config can extend another configuration file so shared compiler settings — like a company-wide strictness baseline — can be reused across multiple projects instead of duplicated in every tsconfig.json.
Example: Extending Configuration
// tsconfig.json
// { "extends": "./tsconfig.base.json", "compilerOptions": { "outDir": "dist" } }
console.log("extends reuses a shared base config across multiple projects");
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: