#Recommended Enum usage with Prisma and Zod

6 messages · Page 1 of 1 (latest)

wind locust
#

Currently, I have enums in my Prisma models which are also redefined in Zod schemas like this:

export const ItemRequestStatusEnum = z.nativeEnum(ItemRequestStatus);
export type ItemRequestStatusType = z.infer<typeof ItemRequestStatusEnum>;

Then, I may reference the type in my code like this:

interface ItemRequestTableProps {
  statusFilter: ItemRequestStatusType;
}

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?

minor owlBOT
#

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!

wind locust
#

On a related note, does it make any difference if I'm importing the enums from "generated/prisma/client" vs "generated/prisma/enums"?

elder frigate
#

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.