Phased migration from Zod v3 to v4 in a monorepo: type mismatch with zodResolver (TS2769) #5443
-
|
Hello. I'm working on a phased migration from zod v3 to v4 in a monorepo, but it isn't going well. We're trying to run zod v3 and v4 side by side via an alias, but we can't get Below is our current project structure (the client is where the error remains unresolved).
Directory structureImplementation examples
// core-v2/src/schemas.ts
import { z } from "zod-v4";
type zLocalType = typeof z;
export const createUserRequestSchemaBuilder = (zLocal: zLocalType) =>
zLocal.object({
name: zLocal.string().min(1).max(100),
email: zLocal.string().email(),
age: zLocal.number().int().positive().optional(),
});
export const createUserRequestSchema = createUserRequestSchemaBuilder(z);
// client/src/hooks/useUserForm.ts
import { zodResolver } from "hookform-resolvers-v5/zod";
import { createUserRequestSchema } from "core-v2/src/schemas";
import { useForm } from "react-hook-form";
import { z } from "zod-v4";
type CreateUserRequest = z.infer<typeof createUserRequestSchema>;
const formMethods = useForm<CreateUserRequest>({
resolver: zodResolver(createUserRequestSchema), // 'No overload matches this call' error occurs here (see below)
defaultValues: {
name: "",
email: "",
age: undefined,
},
});
// server/src/schema/user.ts
import { z } from "@hono/zod-openapi";
import { userSchemaBuilder } from "core-v2/src/schemas";
/**
* User schema (for Hono)
*/
const userSchemaForHono = userSchemaBuilder(z).openapi("User");
// client/src/hooks/useUserForm.ts
import { zodResolver } from "hookform-resolvers-v5/zod";
import { createUserRequestSchema } from "core-v2/src/schemas";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { z } from "zod-v4";
type CreateUserRequest = z.infer<typeof createUserRequestSchema>;
const useUserForm = () => {
const [submittedData, setSubmittedData] = useState<CreateUserRequest | null>(
null
);
const formMethods = useForm<CreateUserRequest>({
resolver: zodResolver(createUserRequestSchema),// The error below occurs
defaultValues: {
name: "",
email: "",
age: undefined,
},
});
import { zodResolver } from "hookform-resolvers-v5/zod";
import { createUserRequestSchemaBuilder } from "core-v2/src/schemas";
import { z } from "zod/v4";
type CreateUserRequest = z.infer<typeof createUserRequestSchema>;
const createUserRequestSchema = createUserRequestSchemaBuilder(z);
// Argument of type 'typeof import("example-project/node_modules/zod/v4/classic/external")' is not assignable to parameter of type 'typeof import("example-project/packages/core/node_modules/zod/v4/classic/external")'.
// Type 'typeof import("example-project/node_modules/zod/v4/classic/external")' is missing the following properties from type 'typeof import("example-project/packages/core/node_modules/zod/v4/classic/external")': util, httpUrl, hostname, hex, and 14 more.
Information needed
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Hi @tas-ricken! I'm Dosu and I’m helping the zod team. I'm a bot trained on Zod's codebase and issues. Here’s what’s happening and how to move forward: The TS2769 error with Best practices for phased migration in a monorepo:
How to resolve your specific issue:
References and further reading:
If this answers your question, please close the issue. If you need more help, feel free to share a minimal reproduction! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
It seems that the issue can be resolved by using standardSchemaResolver instead of zodResolver in the resolver section of client/src/hooks/useUserForm.ts. import { standardSchemaResolver } from "hookform-resolvers-v5/standard-schema";
...
const useUserForm = () => {
const formMethods = useForm<CreateUserRequest>({
resolver: standardSchemaResolver(createUserRequestSchema),
defaultValues: {
name: "",
email: "",
age: undefined,
},
});References: |
Beta Was this translation helpful? Give feedback.
It seems that the issue can be resolved by using standardSchemaResolver instead of zodResolver in the resolver section of client/src/hooks/useUserForm.ts.
References:
https://github.com/react-hook-form/resolvers/blob/master/standard-schema/src/standard-schema.ts
react-hook-form/resolvers#738