Function either

  • Combine two validators with a logical OR

    Type Parameters

    • T

      The first validated type

    • U

      The second validated type

    Parameters

    Returns Validator<T | U>

    Example

    const isStringOrNull = either(isString, isNull);

    isStringOrNull("") >>
    {
    valid: true,
    parsed: "",
    };

    isStringOrNull(null) >>
    {
    valid: true,
    parsed: null,
    };

    isStringOrNull(1) >>
    {
    valid: false,
    error: "Not a string: 1",
    };