zod
zod copied to clipboard
TypeError: Not assignable to parameter of type ZodType<any, any, any>
I've created this schema
to use in React Hook Form
, but I'm getting an error that I'm not sure how to fix.
import { z } from 'zod';
export const schema = z.object({
email_domains: z.string().min(1, { message: 'At least one domain is required' }),
add_to_groups: z.string(),
expires_at: z.string(),
language: z.string(),
name: z.string().min(1),
});
export type FormValuesType = z.infer<typeof schema>;
import { zodResolver } from '@hookform/resolvers/zod';
import { FormProvider, useForm } from 'react-hook-form';
import { defaultExpiresAt, defaultName } from '@/lib/invite-links';
import {
FormValuesType,
schema,
} from '@/components/InviteLinkCreatePage/schema';
export default function Form() {
const methods = useForm<FormValuesType>({
resolver: zodResolver(schema),
values: {
email_domains: '',
add_to_groups: '',
expires_at: defaultExpiresAt(),
language: '',
name: defaultName(),
},
});
const handleSubmit = (data: FormValuesType) => {
console.log({ data });
};
return (
<FormProvider {...methods}>
...
</FormProvider>
);
}
The error coming back is:
Argument of type 'ZodObject<{ email_domains: ZodString; add_to_groups: ZodString; expires_at: ZodString; language: ZodString; name: ZodString; }, "strip", ZodTypeAny, { ...; }, { ...; }>' is not assignable to parameter of type 'ZodType<any, any, any>'.
The types of 'refine(...)._def.typeName' are incompatible between these types.
Type 'import("/Users/ernstoarllano/Sites/dispel/packages/cweb/node_modules/zod/lib/types").ZodFirstPartyTypeKind.ZodEffects' is not assignable to type 'Zod.ZodFirstPartyTypeKind.ZodEffects'.
Property 'ZodReadonly' is missing in type 'Zod.ZodFirstPartyTypeKind'.