Skip to content

Conversation

@MadL0rd
Copy link

@MadL0rd MadL0rd commented Jan 21, 2026

This PR adds a warning to the Codecs documentation about using z.codec() as a
discriminator in z.discriminatedUnion().

When a discriminator is implemented as a codec, the fast discriminator path
relies on the input (in) schema only, which can cause .encode() to fail with
"No matching discriminator".

The added note highlights this limitation and documents available workarounds
({ unionFallback: true } or avoiding codecs in discriminator fields).

Related issue: #5593

Adds a warning callout to the documentation regarding the use of codecs as discriminators in `z.discriminatedUnion()`.

Explains that the fast path for discriminated unions does not work correctly in the `encode()` direction when using codecs, potentially leading to "No matching discriminator" errors.

Suggests workarounds such as enabling `{ unionFallback: true }` or avoiding codecs in the discriminator field.
@vercel
Copy link
Contributor

vercel bot commented Jan 21, 2026

@MadL0rd is attempting to deploy a commit to the colinhacks Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@pullfrog pullfrog bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blocking issues. This is a helpful documentation addition that accurately describes a real limitation with codecs in discriminated unions. The technical explanation is correct—propValues for codecs is derived from the input schema only (def.in._zod.propValues), so discriminator lookup fails during encode(). The suggested workarounds are valid.

Pullfrog  | View workflow runpullfrog.com𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants