← Back to TypeScript Course | Chapter 1: Introduction to TypeScript | Lesson 6 of 7

tsconfig.json Basics

The tsconfig.json file stores compiler settings for a TypeScript project. It can define which files belong to the project and how TypeScript should check and compile them.

Creating tsconfig.json

A tsconfig.json file is a JSON configuration file placed at the root of a TypeScript project. It tells the TypeScript compiler which files belong to the project and exactly how they should be checked and compiled, so every developer and tool uses the same settings.

Example: Creating tsconfig.json

typescript
// tsconfig.json
// {
//   "compilerOptions": { "target": "ES2020" }
// }
console.log("tsconfig.json configures the whole TypeScript project");

Compiler Options

The compilerOptions property is where most configuration lives, containing settings that control both type checking strictness and the shape of the generated JavaScript. Common options include target, module, strict, rootDir, and outDir.

Example: Compiler Options

typescript
// tsconfig.json
// {
//   "compilerOptions": { "target": "ES2020", "module": "commonjs", "strict": true }
// }
console.log("compilerOptions controls type checking and JS output shape");

Target and Module

The target option controls which JavaScript language version the compiler emits, such as ES2015 or ES2022, affecting which modern syntax gets left alone versus transformed for older environments. The module option separately controls the module system, like CommonJS or ESNext, used in the generated output.

Example: Target and Module

typescript
// tsconfig.json
// {
//   "compilerOptions": { "target": "ES2015", "module": "commonjs" }
// }
console.log("target picks the JS version; module picks the module format");

Strict Type Checking

The strict option is a single switch that enables a broad set of stronger type-checking rules at once, including strict null checks and stricter function types. Turning it on catches far more potential mistakes and is standard practice for new TypeScript projects.

Example: Strict Type Checking

typescript
// tsconfig.json
// { "compilerOptions": { "strict": true } }
let value: number | null = null;
// value.toFixed(2); // strict null checks reject this without a null check
console.log(value);

Including and Excluding Files

The include and exclude settings control which files the compiler actually treats as part of the project, using glob patterns. This matters when a project directory contains generated output, test files, or node_modules that should never be type-checked or recompiled.

Example: Including and Excluding Files

typescript
// tsconfig.json
// {
//   "include": ["src/**/*"],
//   "exclude": ["node_modules", "dist"]
// }
console.log("include/exclude use glob patterns to select project files");
🔒

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.