Add .chain() to incorporate external functions into Zod's method chain
#5463
+128
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issues
Closes #5402
Description
I really like Zod's method chaining style because it's refined and beautiful.
However, I find it a bit disappointing that using external functions breaks this chain.
To solve this issue, I added
.chain()to ZodType.Using this, you can write as follows.
Use cases
(ex: Set common default, min, and max values for an already defined ZodNumber schema.)
P.S.
Following the previous pull request(#5410 Thank you for your review.🙏), I am aware this may also be considered a breaking change. However, since I requested this feature myself, I took responsibility and implemented it.
If you feel this feature is unnecessary, please feel free to reject it.