Skip to content
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

Remove createParams cascade from .array() #3530

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

EthanBehrends
Copy link

See this issue for more context.

Basically, the description for a type was getting unexpectedly duplicated when using .array(). For example:

z.string().describe("a description").array()

// ^ was functionally the same as v

z.array(
  z.string().describe("a description")
).describe("a description")

The issue was not present for z.array()

z.array(z.string().describe("a description")) // works as expected

This unexpected behavior was introduced in a fix trying to ensure that something like z.string().describe("a description").optional() persisted the description after being wrapped by ZodOptional.

While this behavior makes sense for types like ZodOptional or ZodNullable, ZodArray is a completely separate type.

Other types that do this cascading createParams:

  • optional
  • nullable
  • promise
  • or
  • and
  • transform
  • default
  • brand
  • catch

I think the logic makes sense for all of these (maybe or and and are also exceptions? not sure)

Added a test for this as well :)

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.

None yet

1 participant