I have a Prisma enum that I've defined (not in TypeScript), and I'm curious if it's possible to synchronize a TypeScript String enum with the generated Type from the Prisma Client. Here are the key details:
export const GroupInvitationStatus: {
Pending: 'Pending',
Accepted: 'Accepted',
Declined: 'Declined'
};
export type GroupInvitationStatus = (typeof GroupInvitationStatus)[keyof typeof GroupInvitationStatus]
Upon importing GroupInvitationStatus from the Prisma Client, I noticed its contents:
(alias) type GroupInvitationStatus = "Pending" | "Accepted" | "Declined"
My aim is to ensure that every value in the Prisma enum (referenced through the imported type) is specified in my TypeScript string enum.
Is this achievable? I've reviewed the TypeScript documentation on enums and searched for solutions but haven't found one yet.
Is it too much? Should I just stick to using the type directly and skip defining an enum?
Update 1: I came across this solution from Stack Overflow that seems promising for my requirements.
Is there a way to dynamically generate enums on TypeScript based on Object Keys?
However, I am struggling to make TypeScript react to changes made in the Prisma Client, contained within the node modules.
While this alternative seems better, it doesn't address my specific situation. I'm starting to think that using the generated const instead of the type as an enum would work just as effectively.
New update: Here is a Code Sandbox with more context. In "prisma-client.ts," I mimic exports from a node module in my project, and in "target-file.enum.ts," I utilize the exports from the Prisma Client.
https://codesandbox.io/s/sweet-curran-n7ruyt?file=/src/target-file.enum.ts