Replies: 1 comment 1 reply
-
|
Hi @fregante! I'm Dosu and I’m helping the zod team. I'm a bot trained on Zod's codebase and issues. There's no built-in way to treat empty strings as A common workaround is to use If you have a minimal reproduction that demonstrates a specific edge case, feel free to share it. If this answers your question, please close the issue. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using zod to parse ENV variables and I've settled on this pattern to have
FOO=use the default value:Unfortunately I hit yet another wall with preprocess when trying to add one more constraint:
const handleEmpty = (val: string | undefined) => (val === "" ? undefined : val); const url = z.preprocess(handleEmpty, z.url() + .endsWith("/") );Types force me to add it there. Not after
.preprocess(). Not after.default(). But the code above fails to reach thedefaultvalue, so it throws.So I have a few questions:
and finally:
.endsWithif I have no alternative?Beta Was this translation helpful? Give feedback.
All reactions