aboutsummaryrefslogtreecommitdiff
path: root/utils/types/brand.ts
blob: d1b7977865cbed1cd73052ae7e6f099ffbe461bb (plain)
1
2
3
4
5
6
7
8
9
10
11
/**
 * Nominal / branded type: compile-time-only tag to distinguish otherwise
 * structurally-equal types.
 *
 *   type PersonId = Brand<string, 'PersonId'>
 *   type RelId = Brand<string, 'RelationshipId'>
 *
 * PersonId and RelId are still strings at runtime but aren't assignable
 * to each other without an explicit cast.
 */
export type Brand<T, B extends string> = T & { readonly __brand: B }