Regular expression matching ECMAScript Identifier names.
Wildcard symbol for open template validation in isObject.
Nullable value.
Optional value.
Defined value.
ECMAScript primitive value.
ECMAScript Identifier.
Immutable JSON value.
Immutable JSON scalar.
Immutable JSON array.
Immutable JSON object.
A type guard function.
Extracts the union of guarded types from an array of type guards.
Extracts the intersection of guarded types from an array of type guards.
A value or a function returning a value.
The eager counterpart of a Lazy reference.
Checks if a value is Nullable.
Checks if a value is Optional.
Checks if a value is Defined.
Checks if a value is a Primitive.
Checks if a value is a valid Identifier.
Checks if a value is a symbol.
Checks if a value is a function.
Checks if a value is an Error instance.
Checks if a value is a RegExp instance.
Checks if a value is a Date instance.
Checks if a value is a promise.
Checks if a value is thenable.
Checks if a value is iterable.
Checks if a value is async iterable.
Checks if a value is a valid JSON value.
Checks if a value is null.
Checks if a value is a JSON scalar.
Checks if a value is a boolean.
Checks if a value is a finite number.
Checks if a value is a string.
Checks if a value is an array.
Checks if a value is a plain object.
Wildcard type guard that always succeeds.
Checks if a value satisfies any of the provided type guards.
Checks if a value satisfies all the provided type guards.
Checks if a value is a Lazy reference.
Checks if a value is an Eager reference.
Defers a value to first use.
Resolves a Lazy reference to its value.
Validates a value against a type guard or a predicate.
Throws an error in expression contexts.
Applies a mapper to a value.
Applies a mapper to an optional value, short-circuiting an undefined one.
Core types, guards, and utilities.
Bridges the gap between TypeScript's static type system and untrusted runtime data. Every guard returns a boolean and narrows its argument on success, so validation and type inference collapse into a single call at API boundaries, deserialisation sites, and other trust-crossing points. Companion utilities work along the same lines, deferring values to first use, binding a value to a mapper of its own with or without a tolerance for its absence, and reporting failures where a statement isn't allowed.
Emptiness Guards
isNullable, isOptional and isDefined settle how the empty values are treated at a given boundary: both markers admitted,
undefinedalone admitted, or presence required. A type guard constrains whatever each of them accepts beyond emptiness, required by the first two and optional for the last, and the results narrow through the matching Nullable, Optional and Defined type operators.Built-in Guards
Guards for language-level values and host objects.
JSON Guards
Complete coverage of the JSON data model: the recursive Value type, its Scalar leaves, and structural guards for arrays and objects. isArray and isObject validate shape in depth through element predicates or tuple/template descriptors; object templates are closed by default, with the key wildcard turning them open.
Composable Guards
Higher-order guards that combine simpler ones into arbitrary type expressions: isUnion for
A | Band isIntersection forA & B. isAny acts as a wildcard that always succeeds, typically used as a placeholder inside templates.Deferred Values
isLazy admits values supplied either eagerly or as no-arg factories; isEager is its dual, rejecting factories and accepting only plain values. Paired with the Lazy / Eager type operators. lazy defers a reference behind a memoising accessor that computes it at most once on first use; eager is its converse, resolving a reference to its value on every call.
Error Reporting
assert validates a value against a type guard or an arbitrary predicate, returning it unchanged on success and throwing a
TypeErrorotherwise, with a message derived from the predicate name or computed from the offending value; guards narrow the result to the guarded type, while plain predicates leave it at its declared type.error throws where a statement isn't allowed, turning a failure into an expression:
Errorcauses are thrown as they are, anything else wrapped in a genericErrorreporting its string representation.Functional Idioms
Bind a value to a mapper of its own, so a computation reads as a scoped expression rather than as a temporary variable followed by a statement, with the bound name free to shadow the one the value was computed from. map always calls the mapper, whatever the value; opt extends the same mapper with a tolerance for a missing value, short-circuiting to
undefinedwithout calling it, or to a fallback of its own, supplied either outright or deferred until the value actually turns out to be missing. Definedness is about assignment rather than emptiness, sonullis mapped like any other value.