Use Prisma Enums in Runtime Validator

Can I use Prisma's generated enums in a zod runtime validator? I have in the @prisma/client this:
export const Language: {
EN: 'EN',
SV: 'SV',
};

export type Language = (typeof Language)[keyof typeof Language]
export const Language: {
EN: 'EN',
SV: 'SV',
};

export type Language = (typeof Language)[keyof typeof Language]
the goal is to do something like
const LanguageValidator = z.enum(Language);
const LanguageValidator = z.enum(Language);
but the Language isn't a real object. is there any workarounds to do this?
2 Replies
iDarkLightning
z.nativeEnum should work, no?
julius
juliusOP3y ago
Thanks, didn't know that was a thing. Works like wonders

Did you find this page helpful?