Z
Zod6mo ago
Gludek

Gludek - Just to confirm z.string().email() can...

Just to confirm z.string().email() can't be combined with .nullish() right?
Solution:
Perhaps you're looking for:
const schema = z.literal("").or(z.string().email());
const schema = z.literal("").or(z.string().email());
...
Jump to solution
6 Replies
Sikari
Sikari6mo ago
I don't see why it wouldn't be able to, nullish just adds undefined | null to the type.
Gludek
Gludek6mo ago
yeah, but regex validation of .email makes it so it needs to be defined, and null/undefined input is treated as invalid
Gludek
Gludek6mo ago
No description
No description
Sikari
Sikari6mo ago
Your form most likely is not passing null or undefined, most likely you have ""
Solution
Sikari
Sikari6mo ago
Perhaps you're looking for:
const schema = z.literal("").or(z.string().email());
const schema = z.literal("").or(z.string().email());
Gludek
Gludek6mo ago
okay that works
Want results from more Discord servers?
Add your server