Configuration inheritance

Often a project has multiple output targets, e.g. ES5 and ES2015, debug and production or CommonJS and System;Just a few configuration options change between these two targets, and maintaining multiple tsconfig.json files can be a hassle.

TypeScript 2.1 supports inheriting configuration using extends, where:

  • extends is a new top-level property in tsconfig.json (alongside compilerOptions, files, include, and exclude).
  • The value of extends must be a string containing a path to another configuration file to inherit from.
  • The configuration from the base file are loaded first, then overridden by those in the inheriting config file.
  • Circularity between configuration files is not allowed.
  • files, include and exclude from the inheriting config file overwrite those from the base config file.
  • All relative paths found in the configuration file will be resolved relative to the configuration file they originated in.
Example

configs/base.json:

  1. {
  2. "compilerOptions": {
  3. "noImplicitAny": true,
  4. "strictNullChecks": true
  5. }
  6. }

tsconfig.json:

  1. {
  2. "extends": "./configs/base",
  3. "files": [
  4. "main.ts",
  5. "supplemental.ts"
  6. ]
  7. }

tsconfig.nostrictnull.json:

  1. {
  2. "extends": "./tsconfig",
  3. "compilerOptions": {
  4. "strictNullChecks": false
  5. }
  6. }