← Back to TypeScript Course | Chapter 17: TypeScript Configuration | Lesson 1 of 7

tsconfig.json Deep Dive

The tsconfig.json file tells TypeScript how to compile a project. It controls the source files, output JavaScript, module system, type checking, and many other compiler behaviors.

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

typescript
// 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

typescript
// 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

typescript
// 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

typescript
// 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

typescript
// 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.