Enums should support an omit method
See original GitHub issueExample of what has to be done right now:
const a = z.nativeEnum( { a: 1, b: 2 } as const )
const b = z.nativeEnum( Remeda.omit( a._def.values, [ 'a' ] ) )
b._def.values.b // works
b._def.values.a
// ^
// Property 'a' does not exist on type 'Omit<{ readonly a: 1; readonly b: 2; }, "a">'.
I’m not sure how to do it with zod enums actually.
This issue would be asking for native and zod enums though to support an omit method.
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
How can I guarantee that my enums definition doesn't change ...
Enums should not be thought of as strings or numbers; they are abstract data types. It should not be possible to "output the...
Read more >How to make the most of Java enums - Oracle Blogs
Anytime you have a set of known constant values, an enum is a type-safe representation that prevents common problems.
Read more >Handbook - Enums - TypeScript
Enums allow a developer to define a set of named constants. Using enums can make it easier to document intent, or create a...
Read more >Enum in Java - DigitalOcean
Enum constructors are always private. We can't create instance of enum using new operator. We can declare abstract methods in java enum, then ......
Read more >Enumeration types - C# reference - Microsoft Learn
You cannot define a method inside the definition of an enumeration type. To add functionality to an enumeration type, create an extension ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s how you do it with zod enums
The inferred type of this this enum is
1 | 2
so you’d omit a literal2
to remove that option.You could also do this:
Yep that’s what I mean by “add the
.omit
method on the baseZodType
”. This would add the.omit
method to all Zod schemas.