V4: `discriminatedUnion.options` returns `undefined`, but types are valid in TypeScript · Issue #4394 · colinhacks/zod · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import{z}from'zod/v4';constMyResult=z.discriminatedUnion([z.object({status: z.literal('success'),data: z.string()}),z.object({status: z.literal('failed'),error: z.string()}),]);// Works as expected.MyResult.def.options.length;// Does not work.// I understand this is considered a legacy approach,// yet TypeScript still treats this as valid code.// This will throw a TypeError at runtime because `options` is `undefined`.MyResult.options.length;
The text was updated successfully, but these errors were encountered:
Zod version:
zod@3.25.0-beta.20250517T081109
The text was updated successfully, but these errors were encountered: