Validates a value against a type guard and returns it at the guarded type.
Returns the value unchanged if the guard accepts it, narrowed to the guarded type; otherwise, throws a TypeError
reporting the expected type, as read from the name of the guard when it is in isXxx form (for example,
isAsyncIterable produces "expected
The declared type of the value to validate
The type guarded by guard
The value to validate, whatever its declared type
The Guard to apply to value, declared over its type or over any supertype of it
Optionalmessage: string | ((value: T) => string)Optional custom error message, either a string or a factory computing it from the offending value;
factories are evaluated only if guard fails, so building expensive messages costs nothing on success; defaults to
a message derived from the guard function name
The value argument, unchanged, typed as G
TypeError When guard returns false
Validates a value against a predicate and returns it.
Returns the value unchanged if the predicate accepts it; otherwise, throws a TypeError reporting the expected
type, as read from the name of the predicate when it is in isXxx form (for example, isString produces
"expected
A plain predicate carries no narrowing information, so the result keeps the declared type of the value, whatever the predicate tests for.
The declared type of the value to validate
The value to validate
The predicate to apply to value, declared over its type or over any supertype of it
Optionalmessage: string | ((value: T) => string)Optional custom error message, either a string or a factory computing it from the offending value;
factories are evaluated only if predicate fails, so building expensive messages costs nothing on success; defaults
to a message derived from the predicate function name
The value argument, unchanged
TypeError When predicate returns false
Validates a value against a type guard or a predicate.