import * as fun from "https://deno.land/x/fun@v2.0.0/refinement.ts";
The Refinement type represents a function that takes a type and returns a
boolean. It denotes a function that narrows a type at runtime. For example
the function (n: unknown): n is number => typeof n === "number"
is the
refinement type Refinement<unknown, number>
. The primary use for Refinement
is to align the runtime value with compile time types.
Variables
The canonical implementation of Schemable for UnknownRefinement. It contains the methods unknown, string, number, boolean, literal, nullable, undefinable, record, array, tuple, struct, partial, intersect, union, and lazy. |
Functions
f and | Compose two refinements into a new refinement that returns true if both of the two input refinements return true. |
Turn a | |
An instance of | |
Compose two refinements, A -> B and B -> C creating a | |
Construct a refinement from a function (a: A) => Either<J, I> where Left denotes that a type does not satisfy the refinement. | |
Construct a refinement from a function (a: A) => Option where None denotes that a type does not satisfy the refinement. | |
f id | Create a identity refinement that always returns true as at the type level a type A is always a type A. |
Intersect is an alias of and. | |
An instance of | |
Creates an instance | |
An instance of | |
f lazy | Lazy is used to handle the case where a refinement is recursive. |
Creates an instance of | |
Turn a | |
An instance of | |
f or | Compose two refinements into a new refinement that returns true if either of the two input refinements return true. |
Create a Refinement from a struct of refinements, where each index of a type much match the originated refinement type, key for key, or not have that property at all. This is distinct from the property being null or undefined. | |
Turn a | |
An instance of | |
Create a Refinement from a struct of refinements, where each index of a type much match the originated refinement type, key for key. | |
Create a Refinement from an array of refinements, where each index of a type much match the originated refinement type. | |
Turn a | |
Union is an alias of or. | |
An instance of |
Interfaces
Specifies Refinement as a Higher Kinded Type, with covariant parameter B corresponding to the 0th index of any substitutions and contravariant parameter A corresponding to the 0th index of any substitutions. | |
Specifies Refinement<unknown, B> as a Higher Kinded Type, with covariant parameter B corresponding to the 0th index of any substitutions. |
Type Aliases
A type that matches any refinement type. | |
The refinement type is a function that returns a boolean indicating that a value satisfies a type. | |
T ToIn | The ToIn type takes a Refinement type and returns the type of its input. |
The ToOut type takes a Refinement type and returns the type of its output refinement. |