Repository navigation
fix: add options to invalid discriminator errors - #5723
Conversation
- Add options field to invalid_union errors for discriminated unions - Update English locale to display valid discriminator values - Update snapshot test to reflect new behavior - Fixes colinhacks#5670
There was a problem hiding this comment.
Low urgency. The runtime behavior is correct and the approach is sound. The main issue is a missing type definition update — options is populated at runtime but not declared on $ZodIssueInvalidUnionNoMatch, so TypeScript users can't access it without a type assertion.
The options field was populated at runtime for discriminated union errors but not declared on the interface, requiring type assertions to access it. This adds the missing type definition.
|
@pullfrog re-review |
There was a problem hiding this comment.
No new issues. Reviewed the following changes:
- Added
readonly options?: util.Primitive[]to$ZodIssueInvalidUnionNoMatchso TypeScript users can access discriminator options without a type assertion
Prior review feedback:
- Declare
optionson$ZodIssueInvalidUnionNoMatchinerrors.ts— addressed inb906dc8
Claude Opus | 𝕏
|
Merged. Nice to have Note: this comment was produced by an AI coding assistant. |
|
Landed in Zod 4.4 |


Title:
Description:
After
{ "code": "invalid_union", "discriminator": "type", "options": ["fruit", "vegetable"], "message": "Invalid discriminator value. Expected 'fruit' | 'vegetable'" }Testing
Fixes #5670