Skip to content

Commit

Permalink
Update generated-types.md
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasburk committed Mar 23, 2020
1 parent 15ed77a commit 8ea33c6
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions docs/prisma-client-js/generated-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ type UserPersonalData = {
}
```
While this is certainly feasible, this approach increases the maintenance burden upon changes to the Prisma schema as you need to manually maintain the types. A cleaner solution to this is to use the `UserGetIncludePayload` and `UserGetSelectPayload` types that are generated and exposed by Prisma Client JS:
While this is certainly feasible, this approach increases the maintenance burden upon changes to the Prisma schema as you need to manually maintain the types. A cleaner solution to this is to use the `UserGetPayload` type that is generated and exposed by Prisma Client:
```ts
// Define a type that includes the relation to `Post`
type UserWithPosts = UserGetIncludePayload<{
posts: true
import { UserGetPayload } from "@prisma/client";

// Define a type that includes the relation to `Post`
type UserWithPosts = UserGetPayload<{
include: { posts: true }
}>

// Define a type that only contains a subset of the scalar fields
type UserPersonalData = UserGetSelectPayload<{
email: true;
name: true;
type UserPersonalData = UserGetPayload<{
select: { email: true; name: true }
}>
```
Expand Down Expand Up @@ -112,4 +113,4 @@ With the `PromiseReturnType` that is exposed by Prisma Client, you can solve thi
import { PromiseReturnType } from '@prisma/client'

type UsersWithPosts = PromiseReturnType<typeof getUsersWithPosts>;
```
```

0 comments on commit 8ea33c6

Please sign in to comment.