Skip to content

Brand

Brand<T, BrandName> = T & object

Defined in: common.ts:26

Branded type utility for nominal typing.

Creates a type that is structurally compatible with T but nominally distinct. Useful for creating type-safe identifiers that can’t be accidentally mixed up.

readonly __brand: BrandName

T

The underlying type

BrandName

A unique string literal to brand the type

type UserId = Brand<number, 'UserId'>
type OrderId = Brand<number, 'OrderId'>
// These are incompatible despite both being numbers:
const userId: UserId = 1 as UserId
const orderId: OrderId = userId // Type error!