Skip to main content
Module

x/ts_brand/mod.ts

Reusable type branding in TypeScript
Latest
import * as tsBrand from "https://deno.land/x/ts_brand@0.0.1/mod.ts";

Functions

A generic function that, when given some branded type, can take a value with the base type of the branded type, and cast that value to the branded type. It fulfills the contract of a Brander.

Produces a Brander<B>, given a brand type B. This simply returns identity but relies on type inference to give the return type the correct type.

Type Aliases

An AnyBrand is a branded type based on any base type branded with any branding type. By itself it is not useful, but it can act as type constraint when manipulating branded types in general.

BaseOf is a type that takes any branded type B and yields its base type.

A Brand is a type that takes at minimum two type parameters. Given a base type Base and some unique and arbitrary branding type Branding, it produces a type based on but distinct from Base. The resulting branded type is not directly assignable from the base type, and not mutually assignable with another branded type derived from the same base type.

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.