#Create a type for `FindUnique` with Includes

1 messages · Page 1 of 1 (latest)

pseudo mortar
#

I usually run my query like this:

const x = await prisma.profile.findUnique({
  where: { id: session.user.profileId }, include: { department: true }
})

This results in a nicely typed object and I am pretty happy. However my framework requires me to define the return type of that query "manually" in a .d.ts file. I saw there are some helpers for Prisma:

https://www.prisma.io/docs/orm/prisma-client/type-safety?query=payload&page=1#type-utilities
and
https://www.prisma.io/docs/orm/prisma-client/type-safety?query=payload&page=1#type-utilities

I played around with this, but no success. How can I "handcraft" the return type for the operation above?

Prisma

Prisma Client provides full type safety for queries, even for partial queries or included relations. This page explains how to leverage the generated types and utilities.

#

The closest I got was this:

let _: Prisma.ProfileGetPayload<{ include: { department: true } }>

This is half way there! The returned type is fine but the input for ProfileGetPayload is not validated at all. I can for example use "departments" instead of "department" (spelling error) and no error would be raised.

Can I somehow use Prisma.Args? Or maybe Prisma.validator?