Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions zod/src/__tests__/zod-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,14 @@ describe('zodResolver', () => {
}>
>();
});

it('should accept z.ZodType', () => {
// https://github.com/react-hook-form/resolvers/issues/782
const schema: z.ZodType<{ id: number }> = z.object({ id: z.number() });
const resolver = zodResolver(schema);

expectTypeOf(resolver).toEqualTypeOf<
Resolver<{ id: number }, unknown, { id: number }>
>();
});
});
10 changes: 2 additions & 8 deletions zod/src/zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -143,9 +139,7 @@ type NonRawResolverOptions = {
interface Zod3Type<O = unknown, I = unknown> {
_output: O;
_input: I;
_def: {
typeName: string;
};
_def: object;
}

// some type magic to make versions pre-3.25.0 still work
Expand Down