Function optional

  • Allow a validator to accept undefined inputs

    Type Parameters

    • T

      The validated type

    Parameters

    Returns Validator<undefined | T>

    Example

    interface Person {
    name?: string;
    }

    const isPerson = isRecordOf<Person>({ name: optional(isString) });

    isPerson({}) >>
    {
    valid: true,
    parsed: { name: undefined },
    };

    isPerson({ name: "Joel" }) >>
    {
    valid: true,
    parsed: { name: "Joel" },
    };