#Type error with zod resolver and schema

18 messages · Page 1 of 1 (latest)

dire nacelle
#

Hi guys, I'm just starting with zod. I'm trying to use it with react-hook-form but I can't figure out the types. there is a type error when I use zodResolver

  title: z.string(),
  report: z.string().optional(),
});

type TCreateRecordSchema = z.infer<typeof CreateRecordSchema>;

export default function CreateRecordForm() {
  const {
    register,
    handleSubmit,
    formState: { errors, isSubmitting },
    reset,
  } = useForm<TCreateRecordSchema>({
    resolver: zodResolver(CreateRecordSchema),
  });```

This is the error 
```Argument of type 'ZodObject<{ title: ZodString; report: ZodOptional<ZodString>; }, "strip", ZodTypeAny, { title: string; report?: string | undefined; }, { title: string; report?: string | undefined; }>' is not assignable to parameter of type 'ZodType<any, any, any>'.
  The types of 'refine(...)._def.typeName' are incompatible between these types.
    Type 'import("E:/myWeb_yearly/1402/06.23_upload-form/node_modules/.pnpm/[email protected]/node_modules/zod/lib/types").ZodFirstPartyTypeKind.ZodEffects' is not assignable to type 'Zod.ZodFirstPartyTypeKind.ZodEffects'.
      Property 'ZodReadonly' is missing in type 'Zod.ZodFirstPartyTypeKind'.ts(2345)```

and you can check my repo from here
https://github.com/rezarahem/record-app/blob/main/components/record-form/CreateRecordForm.tsx
I add photo that shows the error
thanks
GitHub

Contribute to rezarahem/record-app development by creating an account on GitHub.

peak bloomBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

slender sigil
#

if you hover over the error what does it say?

#

if you run next build or next start what is the error when it blows up?

#

Or does it actually work?

#

Your code looks right, so it might be some VSCode nonsense

slender sigil
#

does it build?

#

oh no, that is from a build error

dire nacelle
#

yep it works with run dev. but I have implement anything yet.

#

just a form

slender sigil
#

I would try to restart VS code

#

sometimes it gives me absurd type errors that it just can't forget about

dire nacelle
#

ok

slender sigil
#

because again, the code looks perfect

dire nacelle
#

restart didn't worked same behaviour

slender sigil
#

maybe remove the next cache .next folder, and try next build

#

but like npm build or whatever