Advertisement
Advanced TypeScript, tsconfig & Compiler Options

How do 'extends' in tsconfig.json enable sharing a base configuration across multiple projects in a monorepo, and how do overrides get merged?

Short answer

'extends' points to a base tsconfig file whose compilerOptions are inherited as defaults; the extending file's own compilerOptions are then MERGED on top, with the extending file's values taking precedence for any overlapping keys — letting a monorepo maintain one shared…

Save TypeScript mock interview
Advertisement
AModel answer
'extends' points to a base tsconfig file whose compilerOptions are inherited as defaults; the extending file's own compilerOptions are then MERGED on top, with the extending file's values taking precedence for any overlapping keys — letting a monorepo maintain one shared 'tsconfig.base.json' while individual packages only specify their differences.
// tsconfig.base.json
{ "compilerOptions": { "strict": true, "target": "ES2020" } }

// packages/app/tsconfig.json
{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": { "outDir": "./dist" } // adds to, doesn't replace, the base config
}
Real-world example
Maintaining consistent strictness and target settings across dozens of packages in a monorepo from one shared base file.
Likely follow-ups
  • Do array-valued options like 'include'/'exclude' MERGE across extends, or does the extending file's array fully REPLACE the base's?
Related topics