-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(enum): return enum from object keys #1216
Conversation
✅ Deploy Preview for guileless-rolypoly-866f8a ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
That conversion from a union to a tuple is some black magic. Love it. I renamed this method to Great PR. 🙌 |
@colinhacks yeah, i became a typescript vodoo master recently. Don't ask me what it cost me 🤣 |
Really cool trick @ecyrbe, discovered half of it to make tuple permutations but didn't occur to me to use the function overload trick to get ordering, nice. Do beware of how TS treats key order differently than JS engines though: z.object({ a: z.string(), '1': z.string() }).keyof()._def.values
// TS says it's ['a', '1']
// JS runtime it's ['1', 'a'] Seems to not be an issue for internal use with zod enum, but thought pointing this out can be of some value since the test cases only have non numeral strings |
This should close this issue: #1085
usage
it allows to extract the keys of a zob object schema as a zod enum.
Tell me if it's ok.