import { type Brand } from "https://deno.land/x/actionify@0.3.0/src/deps/types.ts";
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.
Take care that the branding type is unique. Two branded types that share the same base type and branding type are considered the same type! There are two ways to avoid this.
The first way is to supply a third type parameter, ReservedName
, with a
string literal type that is not __type__
, which is the default.
The second way is to define a branded type in terms of its surrounding interface, thereby forming a recursive type. This is possible because there are no constraints on what the branding type must be. It does not have to be a string literal type, even though it often is.