Course contentsShow
← TypeScript
Lesson 63 of 1,7962. Setup and ToolingFree lesson

extends: Sharing Configuration

Inheriting settings from a base configuration file using extends to share common settings across multiple projects.

extends: Sharing Configuration

What you'll learn: How to reuse TypeScript configurations across multiple projects by inheriting settings from a base file.

The Problem of Duplicate Configuration

Imagine you're managing three TypeScript projects that all need the same compiler settings: strict mode enabled, ES2020 as the target, and source maps turned on. Without extends, you'd copy-paste the same tsconfig.json into each project. When you want to update a setting, you'd need to edit all three files manually—tedious and error-prone.

How extends Works

The extends property lets one tsconfig.json inherit settings from another file. Think of it like a template: you create a base configuration file with your common settings, then individual projects reference it and only specify what's different.

Base configuration (tsconfig.base.json):

{
  "compilerOptions": {
    "strict": true,
    "target": "ES2020",
    "sourceMap": true,
    "esModuleInterop": true
  }
}

Project-specific configuration (tsconfig.json):

{
  "extends": "./tsconfig.base.json",
  "compilerOptions": {
    "outDir": "./dist"
  },
  "include": ["src/**/*"]
}

This project inherits all settings from tsconfig.base.json but adds its own outDir and include rules. If settings conflict, the extending file's values win.

Where This Shines

The extends feature is invaluable in monorepos (multiple related projects in one repository) or when maintaining several apps with similar TypeScript requirements. Update the base file once, and all projects automatically get the change.

Key Takeaway: Use extends to create reusable TypeScript configuration templates, reducing duplication and making project-wide updates effortless.