:wave: Hey folks. Quick Typescript question - how ...
# prisma-client
j
👋 Hey folks. Quick Typescript question - how do I access nested fields when using the auto-generated Typescript interfaces from Prisma Client? For example, the model
User
contains a 1-many link to
Services
. We import the
User
interface but it only has
serviceId
, so in our code
user.service
is generating a typescript error (even though the object is present in the data returned from the DB). Sometimes we access objects several levels deep (i.e.
user.service.booking
), just wondering if there's a recommended approach for this.
n
Hey Jeet 👋 Relation fields are not included by default, so the type would only have scalar fields but you could include relation fields as well. You are looking for this Reference: Using Variations of Generated model type
j
Oooh perfect, thank you!
🙌 1