Skip to main content
Module

x/ts_brand/mod.ts>Brander

Reusable type branding in TypeScript
Latest
type alias Brander
import { type Brander } from "https://deno.land/x/ts_brand@0.0.1/mod.ts";

A Brander is a function that takes a value of some base type and casts that value to a branded type derived from said base type. It can be thought of as the type of a "constructor", in the functional programming sense of the word.

Examples

Example 1

type UserId = Brand<number, 'user'>;
// A Brander<UserId> would take a number and return a UserId
definition: (underlying: BaseOf<B>) => B