test(v3): pin union-in-object inference (issue #2654)#6010
Conversation
Fixes Algora bounty: colinhacks#2654 This PR was AI-assisted (Claude Code) and reviewed by a human before submission.
There was a problem hiding this comment.
Important
packages/zod/src/v3 is in maintenance mode and only accepts critical security fixes — additional tests, features, and bugfixes are out of scope. Equivalent coverage already exists for v4 at generics.test.ts:51 (nested no undefined), which pins exactly this inference for z.object({ inner: z.string().or(z.array(z.string())) }). The original #2654 bug no longer reproduces on either v3 or v4 — see @colorbank's recent comment reaching the same conclusion in #6003.
TL;DR — Adds a v3 regression test pinning the inferred type of a union nested inside z.object for issue #2654. The behavior is correct on current v3 and v4, but the v3 tree is frozen and a parallel v4 test already covers this case, so there's nothing here to merge.
Key changes
- Add v3 regression test for union-in-object inference — pins
z.infer<typeof z.object({ name: z.string().or(z.array(z.string())) })>to{ name: string | string[] }inpackages/zod/src/v3/tests/unions.test.ts.
Summary | 1 file | 1 commit | base: main ← algora/algora-org-triggerdotdev-colinhacks-zod-2654
Scope conflict with v3 maintenance mode
Before: No regression test in v3 for the issue #2654 inference shape.
After: A v3 test asserting{ name: string | string[] }inference for a union object property.
The packages/zod/src/v3 tree is closed to non-security changes. The equivalent v4 test (nested no undefined) already asserts the exact same inference shape for z.string().or(z.array(z.string())) inside z.object, and additionally checks that { inner: undefined } is rejected at runtime — so the failure mode this PR guards against is already covered on the maintained branch.
packages/zod/src/v3/tests/unions.test.ts
Thanks for the careful writeup, but I don't think there's a path to merge this one.
Claude Opus | 𝕏

Summary
Add v3 regression test locking the inferred type for a union nested in z.object so the original #2654 bug can't silently return.
Closes
Fixes Algora bounty: #2654
Disclosure
This PR was AI-assisted (Claude Code) and reviewed by a human before submission.