Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Usage

import * as fun from "https://raw.githubusercontent.com/baetheus/fun/main/newtype.ts";

Newtype presents a type level "rebranding" of an existing type.

It's basic purpose is to create a branded type from an existing type. This is much like using TypeScript type aliases, ie. type MyNumber = number. However, Newtype will prevent the existing type from being used where the Branded type is specified.

§Functions

getCombinable

Retype an existing Combinable from an inner type to a Newtype.

getComparable

Retype an existing Comparable from an inner type to a Newtype.

getInitializable

Retype an existing Initializable from an inner type to a Newtype.

getSortable

Retype an existing Sortable from an inner type to a Newtype.

iso

If the Newtype and its underlying value are referentially transparent (meaning they can always be swapped) then you can create an instance of Iso for the Newtype for mapping back and forth.

prism

If the Newtype and its underlying value are not referentially transparent (meaning they can always be swapped) then you can create an instance of Prism for the Newtype in order to optionally map into the Newtype given some Predicate.

§Type Aliases

AnyNewtype

A type alias for Newtype<any, any> that is useful when constructing Newtype related runtime instances.

Newtype

Create a branded type from an existing type. The branded type can be used anywhere the existing type can, but the existing type cannot be used where the branded one can.

ToValue

Extracts the inner type value from a Newtype.