Zod enums vs Native enums
From what I understood from the documentation of Zod, enum should be use as followed :
But it is also possible to use native enums :
Using native enums seems more easy so, why would I use zod enums ? Have I missed something ?
GitHub
TypeScript-first schema validation with static type inference
TypeScript-first schema validation with static type inference
GitHub
TypeScript-first schema validation with static type inference
TypeScript-first schema validation with static type inference
Solution:Jump to solution
This is how I use enums with Zod :
```javascript
// Single source of truth:
const fishes = ["Salmon", "Tuna", "Trout"] as const...
3 Replies
Matt Pocock
YouTube
Enums considered harmful
TypeScript enums are not great. In almost all cases, I use an 'as const' with a sprinkling of type magic to express them.
Become a TypeScript Wizard with Matt's TypeScript Course:
https://www.totaltypescript.com/
Follow Matt on Twitter
https://twitter.com/mattpocockuk
Solution
This is how I use enums with Zod :
@Benjamin @Romain type: z.nativeEnum(YourPrismaEnum),