Skip to content

Type instantiation is excessively deep and possibly infinite" when using Zod with React Hook Form and @hookform/resolvers #4474

@ahmettavsan

Description

@ahmettavsan

Zod 3.25.20
Typescript 5.7
"turbo": "^2.5.3",

i am receiving Type instantiation is excessively deep and possibly infinite.ts(2589)

import { useForm } from "react-hook-form";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
import {
  Form,
  FormField,
  FormItem,
  FormLabel,
  FormControl,
  FormMessage,
} from "./form";

import { Input } from "./input";
import { Button } from "./button";

const formSchema = z.object({
  name: z.string().min(2, { message: "İsim en az 2 karakter olmalı" }),
  email: z.string().email({ message: "Geçerli bir e-posta girin" }),
});
type FormSchema = {
  name: string;
  email: string;
};

export default function UserForm() {
  const form = useForm<FormSchema>({
    resolver: zodResolver(formSchema),
    defaultValues: {
      name: "",
      email: "",
    },
  });

  const onSubmit = (values: FormSchema) => {
    console.log("Form gönderildi:", values);
  };

  return (
    <Form {...form}>
      <form
        onSubmit={form.handleSubmit(onSubmit)}
        className="max-w-md space-y-4"
      >
        <FormField
          control={form.control}
          name="name"
          render={({ field }) => (
            <FormItem>
              <FormLabel>İsim</FormLabel>
              <FormControl>
                <Input placeholder="Adınızı girin" {...field} />
              </FormControl>
              <FormMessage />
            </FormItem>
          )}
        />

        <FormField
          control={form.control}
          name="email"
          render={({ field }) => (
            <FormItem>
              <FormLabel>Email</FormLabel>
              <FormControl>
                <Input
                  type="email"
                  placeholder="E-posta adresinizi girin"
                  {...field}
                />
              </FormControl>
              <FormMessage />
            </FormItem>
          )}
        />

        <Button type="submit">Gönder</Button>
      </form>
    </Form>
  );
}

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