Nullable 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 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 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 matches one of the specified literal values.
Checks if a value is either undefined or satisfies a type guard.
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.
Applies a mapper to a value, short-circuiting an undefined one.
Validates a value against a predicate and returns it.
Throws an error in expression contexts.
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, lifting total mappers over missing arguments, and reporting failures where a statement isn't allowed.
Built-in Guards
Guards for language-level values and host objects. isDefined pairs with the Defined type operator, stripping
undefinedfrom the type of the checked value while retainingnull.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: isLiteral for literal and enum-like sets, isOptional for
T | undefined, isUnion forA | B, and 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.
Functional Idioms
given binds 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; a missing value short-circuits to
undefinedwithout calling the mapper, and the result type follows suit, staying defined for a value that can't beundefinedin the first place.Error Reporting
assert validates a value against 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; validation doesn't narrow, so values are returned at their declared type, whatever type the predicate tests for.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.