Skip to content

declare module 'zod' augmentation breaks when third-party packages load both 'zod' and 'zod/v4' subpaths #379

Open

Description

@CodeWithAlexander

The declare module 'zod' augmentation on ZodType breaks when third-party packages cause TypeScript to load both the top-level zod entry point and the zod/v4 subpath. The top-level zod exports a v3-compat ZodType<Output, Def, Input>, while zod/v4 exports the native v4 ZodType<Output, Input, Internals>. TypeScript merges both into a single ZodType with incompatible type parameters, causing .openapi() to disappear from all schemas.

Minimal repro: install zod@^4 + zod-to-openapi@^8 + langchain + better-auth (or any package whose .d.ts loads zod/v4). npx tsc --noEmit fails. Remove any one of the three ingredients and it passes.

Fix submitted in #378.

Activity

  1. changed the title [-]declare module 'zod' augmentation breaks when third-party packages import from zod/v3[/-] [+]declare module 'zod' augmentation breaks when third-party packages load both 'zod' and 'zod/v4' subpaths[/+] on Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions