CrisOG - Hey! I just read Zod stable is coming ...
Hey! I just read Zod stable is coming out pretty soon - just wanted to know ultimately whats going to be the behavior for the case shown here?
https://github.com/colinhacks/zod/issues/4251
GitHub
v4: Schema key order is no longer preserved · Issue #4251 · colin...
In v3, when using z.object, the parsed return value kept the same key order as defined in the schema. v4 changes how ordering works - it now seems to group required and optional properties separate...
Solution:Jump to solution
This has been settled and the outcome was maintaining the backwards compatibility
9 Replies
Maybe ping colin on Twitter, too, I think he's most responsive there.
Thanks
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Since that was the v3 behavior, I used it at my convenience. Upgraded to v4, and it broke that specific part of the code that relied on it
The specific use case was JSON to XML parsing. The XML parser takes the JSON and uses that specific order, so I just put it in order in the zod schema.
I can work it around no biggie, but it is a breaking change that hasn't been made explicit - which would've been nice
If the new behavior is staying then I'll just fix my code and live with it - but hopefully it's at least put in the changelog/release notes so that people like me that relied on it can easily tell before upgrading
I agree that this is breaking, surprising, and maybe even undesireable. Even Colin's recent post about dropping
z.interface
is harder to grok in his screenshot because the keys get shuffled in the types, too:
My personal take, in order of preference is:
1. Keep the existing schema-shape-driven behavior (no breakage)
2. Switch to input key order (breaking but completely sensical)
3. This new order (breaking but only somewhat sensical)
Unknown User•4mo ago
Message Not Public
Sign In & Join Server To View
Solution
This has been settled and the outcome was maintaining the backwards compatibility
GitHub
v4: Schema key order is no longer preserved · Issue #4251 · colin...
In v3, when using z.object, the parsed return value kept the same key order as defined in the schema. v4 changes how ordering works - it now seems to group required and optional properties separate...