Typescript Union Merging

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…



i’m trying http://twitter.com/zemnmez

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store