While working on large projects there can be scenarios where you run into a situation where multiple declarations share the same name. This can result due to numerous reasons such as geographically distant teams working on a project, new developers unknowingly declare names in a module, while they are unaware of the same name declarations in other modules, which at some point in the future need to work together, merging two subsystems in the same company, to name a few.
When we do run into such scenarios, what would be nice would be a way to seamlessly merge the same name declarations into a common merged declaration, which contains the properties from all the same name declarations. This is possible in TypeScript via declaration merging.
Let's take a look at some basics first. A declaration can create its contents in these three logical categories such as namespace
, type
, and value
. The following table summarizes which declaration maps to which groups:
Declaration | Content... |