Typescript Union Merging

Zemnmez
2 min readOct 19, 2020

Typescript has a concept called ‘Declaration Merging’. The idea is that some kinds of declarations can be specified multiple times, and the ‘final’ or ‘actual’ value is the result of those combined declarations:

interface A { name: string }
interface A { age: number }

Here, we declare using declaration merging to define an interface that is the same as:

interface A { name: string; age: number }

This is really useful for writing code along with contextual, but global type information. Consider this example of…

--

--