Server - Technical Reference - v26.4.1
    Preparing search index...

    Function toNullish

    • Transforms a Zod raw shape by making every property "nullish" (both optional and nullable).

      This utility is useful for creating "Patch" or "Partial" schemas where fields can be explicitly set to null or omitted entirely.

      Type Parameters

      • T extends Readonly<
            {
                [k: string]: $ZodType<
                    unknown,
                    unknown,
                    $ZodTypeInternals<unknown, unknown>,
                >;
            },
        >

      Parameters

      • shape: T

        The Zod raw shape (the internal object structure of a ZodObject).

      Returns { [K in string | number | symbol]: ZodOptional<ZodNullable<T[K]>> }

      A new shape where every key maps to a nullish version of the original schema.

      const bar = z4.object({
      name: z4.string(),
      age: z4.number()
      });

      // Every field in foo is now: string | null | undefined
      const foo = z4.object(toNullish(bar.shape));