Skip to content

wrap

wrap<K, T>(): (value) => Brand<K, T>

Defined in: Types/Brand.ts:38

Returns a constructor that wraps a value of type T in brand K. The resulting function performs an unchecked cast — only use when the raw value is known to satisfy the brand’s invariants.

K extends string

T

(value): Brand<K, T>

T

Brand<K, T>

type PositiveNumber = Brand<"PositiveNumber", number>;
const toPositiveNumber = Brand.wrap<"PositiveNumber", number>();

const n: PositiveNumber = toPositiveNumber(42);