-
-
Notifications
You must be signed in to change notification settings - Fork 245
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
Add support for nested ZodEffects #1382
base: master
Are you sure you want to change the base?
Conversation
Hi @sassanh, thanks for the contribution! It seems we can add it to the upcoming 4 or 4.x version. I will come back with detailed answer and review next week. |
89051a9
to
71b1cd8
Compare
71b1cd8
to
873a776
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sassanh, great job with this pull request. Thanks for your input and adding new tests for the chained refine
and superRefine
functions.
Once those minor adjustments are made, we’ll be glad to proceed with the merge.
export default class ZodBridge<T extends ZodRawShape> extends Bridge { | ||
schema: ZodObject<T> | ZodEffects<ZodObject<T>>; | ||
schema: ZodObject<T> | NestedZodEffect<ZodObject<T>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
schema: ZodObject<T> | NestedZodEffect<ZodObject<T>>; | |
schema: ZodObject<T> | ZodEffects<ZodSchema> |
We decided we don't want to create a special type with depth limit to handle this. ZodEffects<ZodSchema>
will allow nested ZodEffects
type. It will be easier to understand, maintain and we don't want to hardcode specific depth limit.
The downside is that it ZodSchema
allows any zod type. This is something that we need to accept.
Wrong type is still checked using invariant
function in the runtime.
Hi @piotrpospiech, thanks for taking the time to review this! I've made the changes you suggested in the comments. However, regarding your decision to avoid introducing a new type, I wanted to clarify that it does have a trade-off. The error objects returned by Personally, I use Zod because it perfectly aligns with type hints. If I weren't using Zod, I'd use Yup, which is already supported by many libraries. |
Relevant: #1319
This extends what was done in #1319 so that it works when multiple refinements are added, for example:
@piotrpospiech can you kindly take a look?
Do you think we can have it in version 4? It doesn't look like a new feature.