Skip to content

Latest commit

 

History

History
21 lines (13 loc) · 815 Bytes

types.branded.md

File metadata and controls

21 lines (13 loc) · 815 Bytes

Home > @skunkteam/types > Branded

Branded type

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

Remarks

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.