Home > @skunkteam/types > Branded
Create a Branded type with a given BrandName
.
Signature:
type Branded<T, BrandName extends string> = T extends WithBrands<infer Base, infer ExistingBrands>
? WithBrands<Base, BrandName | ExistingBrands>
: WithBrands<T, BrandName>;
References: WithBrands
In order for TypeScript to consider a type separate from another type, we need to brand it. When a type is branded TypeScript will manage correct assignability during TypeScript-compilation, e.g. int
is assignable to number
, but number
is not assignable to int
.