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
Closed
@hibanka

Description

@hibanka

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0