declaration merging
TypeScript combining several declarations with the same name, such as two interface blocks, into one type.
In more detail
It is how you add fields to a type you do not own, for example adding user to a framework's Request interface or DATABASE_URL to ProcessEnv. It works for interfaces and namespaces but not for type aliases.
Related terms
- interface (TypeScript) — In TypeScript, a named description of an object's shape: which properties it has and their types.
- module augmentation — Adding types to another package from your own code with declare module "name" { } and declaration merging.
- global augmentation — Adding types to global objects such as Window or NodeJS.ProcessEnv with a declare global { } block inside a module.
- TypeScript namespace — A TypeScript block, namespace Name { }, that groups declarations under one name and can be merged across files.
Taught in
- Type Aliases Versus Interfaces: Declaration Merging — Production TypeScript
- Tuples: Fixed Length, Labeled Elements And Variadic Tuples — Production TypeScript
- Declaration Files, Ambient Namespaces And Module Augmentation — Production TypeScript