@metreeca/core - v0.9.22
    Preparing search index...

    Function type

    • Constrains a value by type.

      Branches on a type guard, handing a matching value to matched and anything else to unknown. This narrows the value type for the constraints that assume it, while keeping a dedicated branch for values that fail to qualify in the first place.

      unknown is a full validator applied to the non-matching value, free to accept it or report against it. Its default rejects the value, naming the expected type read off the guard name when it follows the conventional isX form of the @metreeca/core guards, for instance isString reporting {type} expected <string> value; a guard named otherwise, an anonymous one among them, is reported against generically.

      Type Parameters

      • T

        The type recognised by guard

      Parameters

      • guard: Guard<T>

        The type guard selecting the branch

      • Optionalmatched: Validator<T>

        The validator applied to a matching value, omitted to accept it unconstrained

      • Optionalunknown: Validator<unknown>

        The validator applied to a value failing guard, omitted to reject it naming the expected type

      Returns Validator<unknown>

      A validator reporting the violations a matching value incurs, and whatever unknown reports for anything else