Z.enum get the input tuple #5339
Replies: 1 comment
-
|
Hi @thibaultdenis014! I'm Dosu and I’m helping the zod team. Zod doesn't expose the original tuple type from a const weightUnitValues = ["kg", "lbs"] as const;
const weightUnit = z.enum(weightUnitValues);
type WeightUnitTuple = typeof weightUnitValues; // readonly ["kg", "lbs"]This is a TypeScript pattern, not a Zod-specific feature. Zod's runtime schema only keeps the values as an array, so the tuple type is only available at the type level when you use If this answers your question, feel free to 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.
-
Hey everyone,
with the following schema, how could I get the type of tuple that is inside the schema ?
I know I can do somehting like
typeof weightUnit.optionsbut its type is not what I am looking for, I get("kg"|"lbs")[], and I wantreadonly ["kg", "lbs"]Beta Was this translation helpful? Give feedback.
All reactions