Skip to content

Update zod validation to support Zod 4 #558

@thebruceyang

Description

@thebruceyang

I ran the zod 4 update docs against server/zod. Hope this helps (at least logs) some required updates:

Key Compatibility Issues:

  1. Internal Structure Access:
    The library heavily relies on accessing ._def directly:

    const typeName: ZodFirstPartyTypeKind | "ConvexId" = zod._def.typeName;

    But the Zod 4 migration guide explicitly states:

    moves ._def
    The ._def property is now moved to ._zod.def.
    

    This is a critical issue that would prevent the library from working correctly with Zod 4.

  2. Function Returns API:
    The library does have some backward compatibility:

    let returns = fn.returns ?? fn.output;

    It checks for both returns and output, which is good, but the core function API in Zod 4 has changed significantly.

  3. Schema Access Pattern:
    Many of the helper functions like zodToConvex and zodOutputToConvex directly access internal properties of Zod schemas that have changed in Zod 4.

What This Means:

  1. This version of convex-helpers is not compatible with Zod 4 without modifications.

  2. You would need:

    • An updated version of convex-helpers specifically built for Zod 4
    • To modify the library code to use ._zod.def instead of ._def
    • To update any other internal structure access patterns
  3. The returns field mentioned in the previous document might work because the library explicitly checks for both returns and output, but the underlying validation mechanism would still fail due to the internal structure changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions