Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I export my model's properties types from Prisma Schema?

Lets say I have this Prisma Schema :

model User {
  id             String   @id @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  email          String   @unique
  username       String   
}

Is there a way I can get lets say email's type in my app ?

  • One options I can come with is a file that will export types but that way everytime I make a change to my prisma schema I will have to go there and manually edit the type.
like image 855
Valeri Avatar asked Oct 15 '25 08:10

Valeri


1 Answers

Prisma by default generates types for all your models. You could import it like this:

import { PrismaClient, User } from '@prisma/client';

Your models will always be in sync with your schema file, anytime you change the schema file, you could execute npx prisma generate to update the PrismaClient and the generated types for your models.

like image 180
Nurul Sundarani Avatar answered Oct 16 '25 20:10

Nurul Sundarani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!