prisma / prisma-client-js

Type-safe database client for TypeScript & Node.js (ORM replacement)
Apache License 2.0
1.47k stars 67 forks source link

No more *GetSelectPayload exported by the client #564

Closed samrith-s closed 4 years ago

samrith-s commented 4 years ago

Hey,

Before installing @prisma/client@2.0.0-alpha.904 and prisma2@2.0.0-alpha.904, I used to get a <Collection>GetSelectPayload for every model.

I used to use it to annotate the arguments to my functions like so:

function checkUserTroup(user: UserGetSelectPayload<{ troups: true }>): boolean {
    return !!user.troups.length;
}

Now, @prisma/client doesn't have any export called UserGetSelectPayload. So I tried this approach:

function checkUserTroup(user: UserGetPayload<UserArgs['select']['troups']>): boolean {
    return !!user.troups.length;
}

But this doesn't work and I get the following errors, which are fairly understandable: image

My question is, is there any replacement for *GetSelectPayload?

Jolg42 commented 4 years ago

Thank you for creating this issue 👍

So indeed UserGetSelectPayload was exported before and documented here but disappeared after the dynamic client changes by @timsuchanek

Now there is indeed UserGetPayload

I don't know any replacement or workaround yet, @timsuchanek will be the best person for that but he's on holiday at the moment. We'll get back as soon as possible 😃

nikolasburk commented 4 years ago

Hey @samrith-s, thanks for opening this issue. I just updated the docs. This is how the new type UserGetPayload can be used:

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 = UserGetPayload<{
  select: { email: true; name: true }
}>
samrith-s commented 4 years ago

Gotcha, thanks! 😄