8000 Unable to extract `set` elements schema · Issue #4373 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Unable to extract set elements schema #4373

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
ThomasAribart opened this issue May 15, 2025 · 2 comments
Closed

Unable to extract set elements schema #4373

ThomasAribart opened this issue May 15, 2025 · 2 comments

Comments

@ThomasAribart
Copy link

Hello and thanks for this wonderful lib!

It seems that contrary to zodOptional.unwrap() , zodList.element or zodUnion.options, I can't get access to the schema of a ZodSet elements 🤔

Is there a method to achieve it? I can try and open a PR if not.

Thomas

@colinhacks
Copy link
Owner

You can always access schema internals via the def.

z.set(z.number())._def.valueType; // Zod 3
z.set(z.number()).def.valueType; // Zod 4

As you can see, the .def is no longer underscore-prefixed in Zod 4 as it's part of the public API. I'm pointing people towards this approach over dedicated methods in Zod 4, which is also why I don't want to adding an .unwrap() method in Zod 3 now. (It's also about to be legacy anyway 🤷‍♂️.)

@ThomasAribart
Copy link
Author

Thanks @colinhacks !

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

No branches or pull requests

2 participants
0