Using a Prisma enum like a TypeScript enum Am I co...
# orm-help
m
Using a Prisma enum like a TypeScript enum Am I correct in assuming that I can basically just use the const generated by the Prisma client like a TypeScript enum? I was trying to dynamically generate an enum based on the output located in the Prisma client, but it seems like essentially I'm just remaking the available const, right?
Copy code
export const GroupInvitationStatus: {
  Pending: 'Pending',
  Accepted: 'Accepted',
  Declined: 'Declined'
};

export type GroupInvitationStatus = (typeof GroupInvitationStatus)[keyof typeof GroupInvitationStatus]
👀 1
a
Hey Michael 👋, It looks like Prisma already exports both the
const
and
type
versions of enums, so you should be safe to just use what Prisma generates. There is no issue with exporting two things of the same name as long as one of them is a
type
and one is a value.
m
Programmatically, an enum is so useful to remove magic strings from code and to limit accepted values. However, I found that the generated
const
is essentially the enum I was looking for - so I am just using that one. It's really nice.