Creates a type predicate function from a guarding.
Wraps a Guard to produce a TypeScript type predicate for use in conditional narrowing.
Caution
Circular references are not supported. Validating objects with cycles causes stack overflow.
Important
For memoization to work, guards must have stable identity. Local functions and lambdas are handled without
memory leaks, but won't be memoized since they lack persistent identity. Use module-level named guards or
const declarations.
Important
Unlike as, this function does not memoize results since it returns a boolean rather than the validated
value. For repeated validation of the same object, ensure it's validated using as beforehand.
Creates a type predicate function from a guarding.
Wraps a Guard to produce a TypeScript type predicate for use in conditional narrowing.
Circular references are not supported. Validating objects with cycles causes stack overflow.
For memoization to work, guards must have stable identity. Local functions and lambdas are handled without memory leaks, but won't be memoized since they lack persistent identity. Use module-level named guards or
constdeclarations.Unlike as, this function does not memoize results since it returns a boolean rather than the validated value. For repeated validation of the same object, ensure it's validated using as beforehand.