8000 V4: `discriminatedUnion.options` returns `undefined`, but types are valid in TypeScript · Issue #4394 · colinhacks/zod · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

V4: discriminatedUnion.options returns undefined, but types are valid in TypeScript #4394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hibanka opened this issue May 17, 2025 · 0 comments

Comments

@hibanka
Copy link
hibanka commented May 17, 2025

Zod version: zod@3.25.0-beta.20250517T081109

import { z } from 'zod/v4';

const MyResult = 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;
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

No branches or pull requests

2 participants
0