feat(typescript-zod): preserve named object unions - #3103
Open
louis-bompart wants to merge 1 commit into
Open
Conversation
louis-bompart
marked this pull request as ready for review
August 4, 2026 10:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Enables
supportsUnionsWithMultipleObjectTypesfor the TypeScript Zod target and extends the named-object-union regression test to cover Zod output.Related Issue
Depends on #3061, which fixes #1646. This is intentionally a stacked draft PR.
Motivation and Context
#3061 adds guarded support for explicitly named, disjoint object alternatives. TypeScript Zod can represent those alternatives directly with
z.union, so it can safely opt in without renderer changes.Previous Behaviour / Output
Zod received the merged optional-properties object produced by the core union-flattening pass. Distinct alternatives such as
FooandBarwere not retained as separate schemas.New Behaviour / Output
The generated Zod output preserves both schemas and references them from the containing schema:
The Zod fixture also rejects an invalid union member.
How Has This Been Tested?
Tested locally with Node.js 24.18.0:
npm run buildnpm run test:unitQUICKTEST=true FIXTURE=schema-typescript-zod npm run test:fixtures -- test/inputs/schema/named-class-union.schemaThe focused fixture round-trips both valid alternatives and verifies that the invalid sample fails.
Screenshots (if appropriate):
Not applicable.