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.
Type Declaration
Section titled “Type Declaration”__brand
Section titled “__brand”
readonly__brand:BrandName
Type Parameters
Section titled “Type Parameters”T
The underlying type
BrandName
Section titled “BrandName”BrandName
A unique string literal to brand the type
Example
Section titled “Example”type UserId = Brand<number, 'UserId'>type OrderId = Brand<number, 'OrderId'>
// These are incompatible despite both being numbers:const userId: UserId = 1 as UserIdconst orderId: OrderId = userId // Type error!