Skip to content
New issue

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

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

Already on GitHub? # to your account

[Zod 4] RFC: ZodIssue formats #3713

Draft
wants to merge 10 commits into
base: v4
Choose a base branch
from
Draft

[Zod 4] RFC: ZodIssue formats #3713

wants to merge 10 commits into from

Conversation

colinhacks
Copy link
Owner

@colinhacks colinhacks commented Aug 16, 2024

Old formats:
https://github.com/colinhacks/zod/blob/v4-rfc-issues/rfcs/v4-issue-formats/old_formats.ts

export type ZodIssue =
  | ZodInvalidTypeIssue
  | ZodInvalidLiteralIssue
  | ZodUnrecognizedKeysIssue
  | ZodInvalidUnionIssue
  | ZodInvalidUnionDiscriminatorIssue
  | ZodInvalidEnumValueIssue
  | ZodInvalidArgumentsIssue
  | ZodInvalidReturnTypeIssue
  | ZodInvalidDateIssue
  | ZodInvalidStringIssue
  | ZodTooSmallIssue
  | ZodTooBigIssue
  | ZodInvalidIntersectionTypesIssue
  | ZodNotMultipleOfIssue
  | ZodNotFiniteIssue
  | ZodCustomIssue;

New formats: https://github.com/colinhacks/zod/blob/v4-rfc-issues/rfcs/v4-issue-formats/new_formats.ts

export type ZodIssue =
  | ZodInvalidTypeIssue
  | ZodInvalidStringIssue
  | ZodInvalidNumberIssue
  | ZodInvalidBigIntIssue
  | ZodInvalidDateIssue
  | ZodInvalidArrayIssue
  | ZodInvalidSetIssue
  | ZodInvalidObjectIssue
  | ZodInvalidFileIssue
  | ZodCustomIssue;

Conceptually speaking these are the major changes:

  1. ZodIssue is a 2-level discriminated union. The first level discriminates on code: invalid_type, invalid_stringm etc. For each code, there are sub-issues that are discriminated with the check field.
  2. Merges invalid_union, invalid_literal, invalid_enum_value into invalid_type
  3. Splits up too_big and too_small across the specific types for which they are defined: invalid_string, invalid_array, etc.
  4. Within each of the type-specific error code (e.g. invalid_string) there is an additional layer of discrimination using the check key. Instead of a top-level ZodNotMultipleOfIssue, this is now a check: "multiple_of" within code: "invalid_string".
  5. Drops invalid_arguments, invalid_return_type, invalid_discriminator_value as these issues are specific to types that will be removed in Zod 4.

@colinhacks colinhacks marked this pull request as draft August 16, 2024 22:16
@colinhacks colinhacks changed the title V4 rfc issues [Zod 4] RFC: ZodIssue format Aug 16, 2024
Copy link

netlify bot commented Aug 16, 2024

Deploy Preview for guileless-rolypoly-866f8a ready!

Name Link
🔨 Latest commit 8bf2cc1
🔍 Latest deploy log https://app.netlify.com/sites/guileless-rolypoly-866f8a/deploys/66bfcffdecd444000843d905
😎 Deploy Preview https://deploy-preview-3713--guileless-rolypoly-866f8a.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@colinhacks colinhacks changed the title [Zod 4] RFC: ZodIssue format [Zod 4] RFC: ZodIssue formats Aug 16, 2024
@colinhacks colinhacks changed the base branch from main to v4 August 16, 2024 22:17
@colinhacks colinhacks marked this pull request as ready for review August 19, 2024 08:26
@colinhacks colinhacks marked this pull request as draft September 3, 2024 22:50
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant