Repository navigation
feat: Implement tuple discriminator detection for union optimization - #5643
mohankumarelec wants to merge 2 commits into
Conversation
|
Pullfrog is configured to use Claude Code, but the associated API key was not provided. To fix this, add the required secret to your GitHub repository:
Alternatively, configure Pullfrog to use a different agent at https://pullfrog.com/console/colinhacks/zod |
agammann
left a comment
There was a problem hiding this comment.
This optimization appears to reject mixed unions that also contain a non-tuple array branch. For example, z.union([z.tuple([z.literal("a")]), z.tuple([z.literal("b")]), z.array(z.string())]).parse(["c"]) should succeed through z.array(z.string()). detectTupleDiscriminator records only the two tuples, then the new loop skips every option when opt is undefined, including the array branch. Could the non-tuple branches remain eligible, with a regression test for this case?
Description
Optimizes union parsing performance by detecting tuple discriminators on the first element. Skips unnecessary validation attempts when the first tuple item is a literal that can discriminate between union branches.
Test plan