From 99b14993bd2c951ce7153c02ee5e2de339786b69 Mon Sep 17 00:00:00 2001 From: Shun Wakatsuki Date: Sat, 23 Aug 2025 13:51:41 +0900 Subject: [PATCH 1/3] fix(zod): remove _def.typeName from Zod3Type to support dynamic schemas again (#782) --- zod/src/zod.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/zod/src/zod.ts b/zod/src/zod.ts index ff55dfc..0217e84 100644 --- a/zod/src/zod.ts +++ b/zod/src/zod.ts @@ -15,11 +15,7 @@ const isZod3Error = (error: any): error is z3.ZodError => { return Array.isArray(error?.issues); }; const isZod3Schema = (schema: any): schema is z3.ZodSchema => { - return ( - '_def' in schema && - typeof schema._def === 'object' && - 'typeName' in schema._def - ); + return '_def' in schema && typeof schema._def === 'object'; }; const isZod4Error = (error: any): error is z4.$ZodError => { // instanceof is safe in Zod 4 (uses Symbol.hasInstance) @@ -143,9 +139,7 @@ type NonRawResolverOptions = { interface Zod3Type { _output: O; _input: I; - _def: { - typeName: string; - }; + _def: object; } // some type magic to make versions pre-3.25.0 still work From 384e0a50bc0b0fd45f2e9e4b0d0dd04cb0a3c4b2 Mon Sep 17 00:00:00 2001 From: Shun Wakatsuki Date: Sat, 23 Aug 2025 14:02:49 +0900 Subject: [PATCH 2/3] test(zod): add test for dynamic schema (#782) --- zod/src/__tests__/zod-v3.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zod/src/__tests__/zod-v3.ts b/zod/src/__tests__/zod-v3.ts index 8e040ba..c2edf55 100644 --- a/zod/src/__tests__/zod-v3.ts +++ b/zod/src/__tests__/zod-v3.ts @@ -175,4 +175,14 @@ describe('zodResolver', () => { }> >(); }); + + it('should accept z.ZodType', () => { + // https://github.com/react-hook-form/resolvers/issues/782 + const schema = z.object({ id: z.number() }) as z.ZodType<{ id: number }>; + const resolver = zodResolver(schema); + + expectTypeOf(resolver).toEqualTypeOf< + Resolver<{ id: number }, unknown, { id: number }> + >(); + }); }); From 1cda243c58d388493dcbeff48c4248a58e254bf7 Mon Sep 17 00:00:00 2001 From: Shun Wakatsuki Date: Sat, 23 Aug 2025 14:28:21 +0900 Subject: [PATCH 3/3] test(zod): replace `as z.ZodType` with type annotation (#782) --- zod/src/__tests__/zod-v3.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zod/src/__tests__/zod-v3.ts b/zod/src/__tests__/zod-v3.ts index c2edf55..a979f10 100644 --- a/zod/src/__tests__/zod-v3.ts +++ b/zod/src/__tests__/zod-v3.ts @@ -178,7 +178,7 @@ describe('zodResolver', () => { it('should accept z.ZodType', () => { // https://github.com/react-hook-form/resolvers/issues/782 - const schema = z.object({ id: z.number() }) as z.ZodType<{ id: number }>; + const schema: z.ZodType<{ id: number }> = z.object({ id: z.number() }); const resolver = zodResolver(schema); expectTypeOf(resolver).toEqualTypeOf<