string type narrowing #381
-
hi! I want to use zod (v3) to validate a string to be one of a few strings like this: However, the type of that property (category) is still I found a way to get the right type out of it using a transform afterwards: This feels verbose and extremely repetitive though. Is there a better way to do this? |
Beta Was this translation helpful? Give feedback.
Answered by
prescience-data
Apr 6, 2021
Replies: 1 comment 2 replies
-
Is there a reason for not using z.object({
category: z.enum(["block", "sound", "lang", "misc"]).default("block")
}) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
meadowsys
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a reason for not using
enum
( which is what this is for )?