Skip to content

Brand

Brand<K, T> = T & object

Defined in: Types/Brand.ts:22

Brand<K, T> creates a nominal type by tagging T with a phantom brand K. Prevents accidentally mixing up values that share the same underlying type.

readonly [_brand]: K

K extends string

T

type UserId = Brand<"UserId", string>;
type ProductId = Brand<"ProductId", string>;

const toUserId = Brand.wrap<"UserId", string>();
const toProductId = Brand.wrap<"ProductId", string>();

const userId: UserId = toUserId("user-123");
const productId: ProductId = toProductId("prod-456");

// Type error: ProductId is not assignable to UserId
// const wrong: UserId = productId;