Skip to content

issue: hookform/resolvers no longer working with Zod v4? #799

@liljamesjohn

Description

@liljamesjohn

Version Number

5.2.0

Codesandbox/Expo snack

N/A

Steps to reproduce

Versions:

  • zod: 4.0.10
  • react-hook-form: 7.61.1
  • @hookform/resolvers: 5.2.0

Issue:
Helper function for easily working with react-hook-form and zod schemas was working perfectly fine with version 3+, but as soon as we upgraded to version 4 it is now outputting the following type error:

Type 'Resolver<input<T>, any, output<T>>' is not assignable to type 'Resolver<output<T>, any, output<T>>'.
  Types of parameters 'values' and 'values' are incompatible.
    Type 'output<T>' is not assignable to type 'input<T>'.
      Type 'unknown' is not assignable to type 'input<T>'.ts(2322)

(property) resolver?: Resolver<z.core.output<T>, any, TFieldValues> | undefined

Helper function code:

import { zodResolver } from "@hookform/resolvers/zod";
import { type UseFormProps, useForm } from "react-hook-form";
import type { z } from "zod";

export const useZodForm = <T extends z.ZodType<any, any>>(
  schema: T,
  options?: Omit<UseFormProps<z.infer<T>>, "resolver">,
) => {
  return useForm<z.infer<T>>({
    resolver: zodResolver(schema),
    ...options,
  });
};

Expected behaviour

Expect no type errors.

What browsers are you seeing the problem on?

No response

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

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