Replies: 1 comment
-
|
As recursive schemas are already planned for Zod 4, I will be closing this discussion 🙏 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone! I implemented a way of defining type-safe recursive schemas for my binary library, and I was wondering if the same could be implemented in Zod to eliminate the current limitation stated in docs 👀.
Essentially, the technique I am proposing would involve a level of indirection when defining such schemas. Here is what that could look like (based on the example by crasite).
This can be seen in action in an equivalent typed-binary example: https://stackblitz.com/edit/vitejs-vite-ngngr1?file=src%2Flinked-list.ts (or as seen on the screenshot)
Potential drawbacks
This does increase the complexity of the
TypeOf,input, andoutputgeneric functions, requiring them to traverse the '_output' and '_input' types recursively.Beta Was this translation helpful? Give feedback.
All reactions