interface-forge - v2.5.0
    Preparing search index...

    Interface ZodOptional<T>

    interface ZodOptional<T extends SomeType = $ZodType> {
        _def: $ZodOptionalDef<T>;
        _input: undefined | input<T>;
        _output: undefined | output<T>;
        _zod: $ZodOptionalInternals;
        "~standard": $ZodStandardSchema<ZodOptional<T>>;
        def: $ZodOptionalDef<T>;
        description?: string;
        spa: (
            data: unknown,
            params?: ParseContext<$ZodIssue>,
        ) => Promise<ZodSafeParseResult<undefined | output<T>>>;
        type: "optional";
        and<T extends SomeType>(incoming: T): ZodIntersection<ZodOptional<T>, T>;
        array(): ZodArray<ZodOptional<T>>;
        brand<T extends PropertyKey = PropertyKey>(
            value?: T,
        ): PropertyKey extends T ? ZodOptional<T> : $ZodBranded<ZodOptional<T>, T>;
        catch(def: undefined | output<T>): ZodCatch<ZodOptional<T>>;
        catch(
            def: (ctx: $ZodCatchCtx) => undefined | output<T>,
        ): ZodCatch<ZodOptional<T>>;
        check(
            ...checks: (
                CheckFn<undefined | output<T>>
                | $ZodCheck<undefined | output<T>>
            )[],
        ): this;
        clone(def?: $ZodOptionalDef<T>, params?: { parent: boolean }): this;
        default(def: undefined | output<T>): ZodDefault<ZodOptional<T>>;
        default(def: () => NoUndefined<output<T>>): ZodDefault<ZodOptional<T>>;
        describe(description: string): this;
        isNullable(): boolean;
        isOptional(): boolean;
        meta(): | undefined
        | {
            deprecated?: boolean;
            description?: string;
            example?: unknown;
            examples?: | unknown[]
            | { [key: string]: { value: unknown; [key: string]: unknown } };
            id?: string;
            title?: string;
            [key: string]: unknown;
        };
        meta(
            data: {
                deprecated?: boolean;
                description?: string;
                example?: unknown;
                examples?:
                    | unknown[]
                    | { [key: string]: { value: unknown; [key: string]: unknown } };
                id?: string;
                title?: string;
                [key: string]: unknown;
            },
        ): this;
        nonoptional(
            params?:
                | string
                | {
                    error?: string
                    | $ZodErrorMap<$ZodIssueInvalidType<unknown>>;
                    message?: string;
                },
        ): ZodNonOptional<ZodOptional<T>>;
        nullable(): ZodNullable<ZodOptional<T>>;
        nullish(): ZodOptional<ZodNullable<ZodOptional<T>>>;
        optional(): ZodOptional<ZodOptional<T>>;
        or<T extends SomeType>(option: T): ZodUnion<[ZodOptional<T>, T]>;
        overwrite(fn: (x: undefined | output<T>) => undefined | output<T>): this;
        parse(
            data: unknown,
            params?: ParseContext<$ZodIssue>,
        ): undefined | output<T>;
        parseAsync(
            data: unknown,
            params?: ParseContext<$ZodIssue>,
        ): Promise<undefined | output<T>>;
        pipe<
            T extends
                $ZodType<
                    any,
                    undefined
                    | output<T>,
                    $ZodTypeInternals<any, undefined | output<T>>,
                >,
        >(
            target:
                | T
                | $ZodType<
                    any,
                    undefined
                    | output<T>,
                    $ZodTypeInternals<any, undefined | output<T>>,
                >,
        ): ZodPipe<ZodOptional<T>, T>;
        prefault(def: () => undefined | input<T>): ZodPrefault<ZodOptional<T>>;
        prefault(def: undefined | input<T>): ZodPrefault<ZodOptional<T>>;
        readonly(): ZodReadonly<ZodOptional<T>>;
        refine(
            check: (arg: undefined | output<T>) => unknown,
            params?:
                | string
                | {
                    abort?: boolean;
                    error?: string
                    | $ZodErrorMap<NonNullable<$ZodIssue>>;
                    message?: string;
                    params?: Record<string, any>;
                    path?: PropertyKey[];
                },
        ): this;
        register<
            R extends
                $ZodRegistry<
                    MetadataType,
                    $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>,
                >,
        >(
            registry: R,
            ...meta: ZodOptional<T> extends R["_schema"]
                ? undefined extends R["_meta"]
                    ? [$replace<R["_meta"], R["_schema"] & ZodOptional<T>>?]
                    : [$replace<R["_meta"], R["_schema"] & ZodOptional<T>>]
                : ["Incompatible schema"],
        ): this;
        safeParse(
            data: unknown,
            params?: ParseContext<$ZodIssue>,
        ): ZodSafeParseResult<undefined | output<T>>;
        safeParseAsync(
            data: unknown,
            params?: ParseContext<$ZodIssue>,
        ): Promise<ZodSafeParseResult<undefined | output<T>>>;
        superRefine(
            refinement: (
                arg: undefined | output<T>,
                ctx: RefinementCtx<undefined | output<T>>,
            ) => void | Promise<void>,
        ): this;
        transform<NewOut>(
            transform: (
                arg: undefined | output<T>,
                ctx: RefinementCtx<undefined | output<T>>,
            ) => NewOut | Promise<NewOut>,
        ): ZodPipe<
            ZodOptional<T>,
            ZodTransform<Awaited<NewOut>, undefined | output<T>>,
        >;
        unwrap(): T;
    }

    Type Parameters

    Hierarchy (View Summary)

    Index

    Properties

    Use .def instead.

    _input: undefined | input<T>

    Use z.input<typeof schema> instead.

    _output: undefined | output<T>

    Use z.output<typeof schema> instead.

    description?: string
    spa: (
        data: unknown,
        params?: ParseContext<$ZodIssue>,
    ) => Promise<ZodSafeParseResult<undefined | output<T>>>
    type: "optional"

    Methods

    • Parameters

      Returns this

    • Parameters

      Returns this

    • Returns a new instance that has been registered in z.globalRegistry with the specified description

      Parameters

      • description: string

      Returns this

    • Returns boolean

      Try safe-parsing null (this is what isNullable does internally):

      const schema = z.string().nullable();
      const isNullable = schema.safeParse(null).success; // true
    • Returns boolean

      Try safe-parsing undefined (this is what isOptional does internally):

      const schema = z.string().optional();
      const isOptional = schema.safeParse(undefined).success; // true
    • Returns the metadata associated with this instance in z.globalRegistry

      Returns
          | undefined
          | {
              deprecated?: boolean;
              description?: string;
              example?: unknown;
              examples?: | unknown[]
              | { [key: string]: { value: unknown; [key: string]: unknown } };
              id?: string;
              title?: string;
              [key: string]: unknown;
          }

    • Returns a new instance that has been registered in z.globalRegistry with the specified metadata

      Parameters

      • data: {
            deprecated?: boolean;
            description?: string;
            example?: unknown;
            examples?:
                | unknown[]
                | { [key: string]: { value: unknown; [key: string]: unknown } };
            id?: string;
            title?: string;
            [key: string]: unknown;
        }

      Returns this

    • Parameters

      Returns this

    • Type Parameters

      • T extends $ZodType<
            any,
            undefined
            | output<T>,
            $ZodTypeInternals<any, undefined | output<T>>,
        >

      Parameters

      • target:
            | T
            | $ZodType<
                any,
                undefined
                | output<T>,
                $ZodTypeInternals<any, undefined | output<T>>,
            >

      Returns ZodPipe<ZodOptional<T>, T>

    • Parameters

      • check: (arg: undefined | output<T>) => unknown
      • Optionalparams:
            | string
            | {
                abort?: boolean;
                error?: string
                | $ZodErrorMap<NonNullable<$ZodIssue>>;
                message?: string;
                params?: Record<string, any>;
                path?: PropertyKey[];
            }
        • string
        • {
              abort?: boolean;
              error?: string | $ZodErrorMap<NonNullable<$ZodIssue>>;
              message?: string;
              params?: Record<string, any>;
              path?: PropertyKey[];
          }
          • Optionalabort?: boolean

            If true, no later checks will be executed if this check fails. Default false.

          • Optionalerror?: string | $ZodErrorMap<NonNullable<$ZodIssue>>
          • Optionalmessage?: string

            This parameter is deprecated. Use error instead.

          • Optionalparams?: Record<string, any>
          • Optionalpath?: PropertyKey[]

      Returns this

    • Type Parameters

      Parameters

      Returns this

    • Parameters

      Returns this

      Use .check() instead.

    • Returns T