Matching types to Prisma models

I have a T3 boilerplate with Prisma and PlanetScale as per Theo's T3 Stack Tutorial. I'm trying to create a dynamic route for a product under /shop that will accept a router query of the product ID. What is the best practice in this environment to create a type for a product, but using the already-existing model in the prisma schema? I could just create my own type, of course, but then that seems like it's a duplication of effort (creating the prisma model AND the type, and having to update both). Any advice would be great. Thank you
Solution:
You can just import the model type from prisma like
import { Product } from '@prisma/client'
import { Product } from '@prisma/client'
where you have a prisma model named "Product"
Jump to solution
3 Replies
oadster
oadster2y ago
Why don't you just use the type from prisma?
Solution
oadster
oadster2y ago
You can just import the model type from prisma like
import { Product } from '@prisma/client'
import { Product } from '@prisma/client'
where you have a prisma model named "Product"
.majamin
.majaminOP2y ago
Thanks, that's exactly it. This is my first time using Prisma, and I'm glad there's a way to do this so easily.
Want results from more Discord servers?
Add your server