Skip to content

Help!! type errors in generated code (Zod v4 support??) #1237

@sotta-tis

Description

@sotta-tis

When using graphql-codegen-typescript-validation-schema together with Zod v4, the generated code produces type errors. The output still assumes the Zod v3 style where input and output types are identical, but in Zod v4 the generics are <Output, Def, Input>, so this no longer works.

Example error:
zod v4.1.5
graphql-codegen-typescript-validation-schema v0.17.1

lib/graphql/validation.ts:
  plugins:
    - typescript-validation-schema
  config:
    schema: zod
    enumsAsTypes: true
    strictScalars: false
    useTypeImports: true
    withObjectType: true
    importFrom: './generated'

// from generated code
[K in keyof T]: z.ZodType<T[K], any, T[K]>;
// -> TS error about '$ZodTypeInternals'

This seems to be caused by the generated definitions not being updated for the Zod v4 type system.

Does anyone know the recommended solution or workaround for this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions