How to get enums in prisma client?

You can access the user_type enum in your application code like this:

import {user_type } from "@prisma/client";

let foo: user_type = "superadmin";
// use like any other type/enum

How you plan to connect this to the client-side or send it there is up to you. Typically Prisma types reside in the server-side of your code, not the client-side, so it might be difficult to import prisma types in your client code directly.

This is how Prisma defines the user_type enum under the hood.

// file: node_modules/.prisma/client/index.d.ts
export const user_type: {
  superadmin: 'superadmin',
  admin: 'admin',
  user: 'user'
};

You could just copy and paste this into your client-side code if you like.

Leave a Comment