Zod - `require_error` in string not working when also using `min`

Does someone know how I can show the required_error in Zod?
z.string({ require_error: "Name is required"}).min(2, { message: "Name must be at least 2 characters"});
z.string({ require_error: "Name is required"}).min(2, { message: "Name must be at least 2 characters"});
when I parse this, it only shows that I need at least 2 characters, even if the string is empty
2 Replies
mrnicericee
mrnicericee2y ago
You passed a '' , that is a valid string. You’re thinking of a falsy string value An empty string is still a string, so it will pass the required error
EQ
EQOP2y ago
Then what is the best way to say that name is required? Or is that not possible? I got it fixed, if you use min 1 in combination with 2, it will work
Want results from more Discord servers?
Add your server