Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refining adds error to "" instead of "root" #3919

Open
mhuggins opened this issue Dec 19, 2024 · 0 comments
Open

Refining adds error to "" instead of "root" #3919

mhuggins opened this issue Dec 19, 2024 · 0 comments

Comments

@mhuggins
Copy link

mhuggins commented Dec 19, 2024

I'm using zod in conjunction with react-hook-form. (I don't think the use of react-hook-form is relevant, but I'm mentioning it just in case.) I have a simple schema defined as follows:

const schema = z
  .object({
    email: z.boolean(),
    slack: z.boolean(),
  })
  .refine(
    (input) => input.email || input.slack,
    { message: "At least one target is required" },
  );

When validation runs, the refinement error "At least one target is required" gets added to a key of "" instead of "root". If I log my errors object to the console, I see:

{
    "": {
        "message": "At least one integration target is required",
        "type": "custom"
    }
}

I'm expecting to see:

{
    "root": {
        "message": "At least one integration target is required",
        "type": "custom"
    }
}

I've tried specifying options for path: [] and path: ["root"] to refine, but neither seems to help. (The former results in the same thing, the latter results in an empty errors object.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant