react-hook-form / resolvers

📋 Validation resolvers: Yup, Zod, Superstruct, Joi, Vest, Class Validator, io-ts, Nope, computed-types, typanion, Ajv, TypeBox, ArkType, Valibot, effect-ts and VineJS
https://react-hook-form.com/
MIT License
1.67k stars 151 forks source link

Typeerror when used with zod 3.23 #675

Open ljukas opened 2 months ago

ljukas commented 2 months ago

Describe the bug When used together with zod 3.23 it will throw type errors in the zodResolver() function, all schemas does this

To Reproduce Use latest release of @hookform/resolvers with zod 3.23

Expected behavior To work with zod 3.23

nkovacic commented 2 months ago

After updating to zod 3.23.8 this issue started appearing for me. Updating @hookform/resolvers to 3.3.4 does not help.

TypeScript error message:

Argument of type 'ZodObject<{ email: ZodString; }, "strip", ZodTypeAny, { email: string; }, { email: string; }>' is not assignable to parameter of type 'ZodType<any, any, any>'.
  The types of '_getOrReturnCtx(...).common.issues' are incompatible between these types.
    Type 'Zod.ZodIssue[]' is not assignable to type 'import("/web/node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/ZodError").ZodIssue[]'.
      Type 'Zod.ZodIssue' is not assignable to type 'import("/web/node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/ZodError").ZodIssue'.
        Type 'ZodInvalidUnionIssue & { fatal?: boolean | undefined; message: string; }' is not assignable to type 'ZodIssue'.
          Type 'Zod.ZodInvalidUnionIssue & { fatal?: boolean | undefined; message: string; }' is not assignable to type 'import("/web/node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/ZodError").ZodInvalidUnionIssue & { fatal?: boolean | undefined; message: string; }'.
            Type 'ZodInvalidUnionIssue & { fatal?: boolean | undefined; message: string; }' is not assignable to type 'ZodInvalidUnionIssue'.
              Types of property 'unionErrors' are incompatible.
                Type 'Zod.ZodError<any>[]' is not assignable to type 'import("/web/node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/ZodError").ZodError<any>[]'.
                  Type 'Zod.ZodError<any>' is not assignable to type 'import("/web/node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/ZodError").ZodError<any>'.
                    Types of property 'issues' are incompatible.
                      Type 'Zod.ZodIssue[]' is not assignable to type 'import("/web/node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/ZodError").ZodIssue[]'.
                        Type 'Zod.ZodIssue' is not assignable to type 'import("/web/node_modules/.pnpm/zod@3.22.4/node_modules/zod/lib/ZodError").ZodIssue'.
                          Type 'ZodInvalidArgumentsIssue & { fatal?: boolean | undefined; message: string; }' is not assignable to type 'ZodIssue'.
Ygilany commented 1 month ago

This issue goes away when downgrading @hookform/resolvers to ^2.0.0

jorisre commented 1 week ago

Can you please provide a minimal reproducible example (e.g. a Codesandbox)?