The following code fragment in this lesson is not producing the results with the latest version of Zod I have installed:
const schema = z.object({
description: z
.string()
.min(3, { message: "Description should be at least 3 characters" })
.max(50),
amount: z
.number({ invalid_type_error: "Amount is required" })
.min(0.01)
.max(100_000),
category: z.enum(categories, {
errorMap: () => ({ message: "Category is required" }),
}),
});
The “Amount is required” message shows as “Amount”.
The code that works is as follows:
const schema = z.object({
description: z
.string()
.min(3, { message: "Description should be at least 3 characters" })
.max(50),
amount: z
.number({
required_error: "Amount is required",
invalid_type_error: "Amount must be a number",
})
.min(0.01)
.max(100_000),
category: z.enum(categories, {
errorMap: () => ({ message: "Category is required" }),
}),
});