Recommended Enum usage with Prisma and Zod
Currently, I have enums in my Prisma models which are also redefined in Zod schemas like this:
Then, I may reference the type in my code like this:
I've started wondering if I should remove the Zod enum/type and simply reference the ItemRequestStatus enum generated by Prisma. Is one approach recommended over the other?
3 Replies
You selected to wait for the human sages. They'll share their wisdom soon.
Grab some tea while you wait, or check out
#ask-ai
if you'd like a quick chat with the bot anyway!On a related note, does it make any difference if I'm importing the enums from "generated/prisma/client" vs "generated/prisma/enums"?
Hey!
If you only need compile time type safety and do not need to validate values at runtime, you can reference the Prisma enum type directly.
Related Issue: https://github.com/prisma/prisma/issues/3528
You shouldn't get any issues if you import from generated/prisma/enums