Is there a way to compose a type for a specific co...
# prisma-client
p
Is there a way to compose a type for a specific combination of
includes
? For example, suppose I have a query like this:
Copy code
prisma.user.findUnique({
  where: { id },
  include: {
    post: true
  },
});
and I want to create a type for the result leveraging the Prisma generated types. something along the lines of this (I’ve just made up the
Includes
helper tho):
Copy code
import { User, Post } from '.prisma/client';
type UserWithPosts = Include<User, Post>;
👍 1
👀 1
or, is the fact that I even want this a smell of some sort? I’m fairly new to both TS and Prisma
r
@Parker Lawrence 👋 This can be done in the following manner:
Copy code
import { Prisma } from '@prisma/client'
type T = Prisma.UserGetPayload<{
  include: { posts: true }
}>
🙌 2
p
@Ryan thanks so much! That seems like exactly what I’m looking for
2