Today I learned about a pattern in Typescript called “Branded Types” which lets you create “nominal” types.

Typescript’s type system is structural which is incredibly flexible and powerful when working with javascript patterns, but occasionally you want to add some extra strictness where even if the shape of the data is the same, you’ll get a type error if the name of the types don’t match (like in C# which is a nominal type system).

A simple example looks like this:

branded type example code

Read more here: https://egghead.io/blog/using-branded-types-in-typescript