@metreeca/type - v0.1.1
    Preparing search index...

    Function is

    • 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.

      Type Parameters

      • T

        The type being validated

      Parameters

      • guarding: Guarding<T>

        The guarding to use for validation

      Returns (v: unknown) => v is T

      A type predicate function returning true when guarding passes

      When the validated value contains circular references