Skip to content

Zod v4 #2828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Zod v4 #2828

wants to merge 1 commit into from

Conversation

david-crespo
Copy link
Collaborator

https://zod.dev/v4

Was curious how the Zod v4 migration would look, so I tried it and it turned out to be easy enough that I finished it. This will remain a draft for now because we need to upgrade oxide.ts to do automatically what I've done here by hand in the generated code:

  • z.string().uuid() -> z.uuid()
  • z.string().ip() -> z.ipv4() or a union of v4 and v6
  • z.record(X) -> z.record(z.string(), X) (they got rid of the single-arg shorthand)
  • Put .nullable() before .default(null) so default knows it can take null

Copy link

vercel bot commented May 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
console ✅ Ready (Inspect) Visit Preview May 19, 2025 7:35pm

paramSchema: ZodSchema | null,
bodySchema: ZodSchema | null
// eslint-disable-next-line @typescript-eslint/no-explicit-any
paramSchema: ZodType<any> | null,
Copy link
Collaborator Author

@david-crespo david-crespo May 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value of the generic param in v3 is any, but in v4 it's unknown, which is better a general practice. We pass in any explicitly to get the old behavior back. It would be nice to fix the code so unknown works, and I might do that, but it's also not worth much. This code is only used in the mock API server and never changes.

@@ -77,7 +77,7 @@ export const snapshots: Json<Snapshot>[] = [
state: 'ready',
},
{
id: '7fc6ca11-452e-d3e4-9e1c-752ff615abea',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out this was an invalid UUID, correctly rejected by Zod because of the d in d3e4, which is supposed to be a 4 for UUID v4.

@david-crespo
Copy link
Collaborator Author

Will reopen when we get to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant