Skip to content

"Expected number, received string" How do I update the values before the parsing validation. #163

Answered by IdoPesok
jericopulvera asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, you can use coerce. It will convert the string to a number before parsing.

export const checkoutFormSchema = z.object({
  cartId: z.string(),
  paymentMethod: paymentMethodSchema,
  items: z.array(z.string()),
  total: z.coerce.number().positive(),
});

For reference, check out coerce in the Zod docs

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by IdoPesok
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants