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

Incorrect parsing from string to number with .refine() #16

Closed
binajmen opened this issue Feb 21, 2022 · 0 comments
Closed

Incorrect parsing from string to number with .refine() #16

binajmen opened this issue Feb 21, 2022 · 0 comments

Comments

@binajmen
Copy link

binajmen commented Feb 21, 2022

As discussed on Discord ;)

When using inputs with type number, the conversion work with the following schema:

const schema = z
  .object({
    min: z.number(),
    max: z.number(),
  })

But not with this one (with .refine()):

const schema = z
  .object({
    min: z.number(),
    max: z.number(),
  })
  .refine((data) => data.min < data.max, {
    message: "Min < Max",
    path: ["min"],
  })

I receive the error:

Expected number, received string
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