Type error with zod resolver and schema
Unanswered
Pacific cod posted this in #help-forum
Pacific codOP
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
This is the error
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
const CreateRecordSchema = z.object({
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/zod@3.22.2/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
17 Replies
Asian black bear
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
@Asian black bear if you run `next build` or `next start` what is the error when it blows up?
Pacific codOP
I added the error
Asian black bear
does it build?
oh no, that is from a build error
Pacific codOP
yep it works with run dev. but I have implement anything yet.
just a form
Asian black bear
I would try to restart VS code
sometimes it gives me absurd type errors that it just can't forget about
Pacific codOP
ok
Asian black bear
because again, the code looks perfect
Pacific codOP
restart didn't worked same behaviour
Asian black bear
maybe remove the next cache
.next folder, and try next buildbut like
npm build or whateverPacific codOP
ok, I'll try