PrismaP
Prisma7mo ago
5 replies
DollarNavalex

Convert Prisma enum to Typescript enum (and opposite)

Hey guys,

I have this Prisma enum:
enum ChallengeMetric {
    STEP_COUNT
    DISTANCE
    VERTICAL_DURATION
    WALK_DURATION
}


And also this typescript enum:
export enum ChallengeMetric {
    STEP_COUNT,
    DISTANCE,
    VERTICAL_DURATION,
    WALK_DURATION
}


The typescript is mainly used by my front. My backend have a class to convert my front object to Prisma typescript object. My problem is I don't know how to convert from my typescript enum to the prisma enum, and transform the prisma enum to my enum.

The only solution that doesn't trigger an typescript error (not tested tho) is:
// Metric is my custom enum, PChallengeMetric is the Prisma enum
metric as unknown as keyof typeof PChallengeMetric,

But it does not work (return undefined)
Was this page helpful?