PrismaP
Prisma2y ago
12 replies
Uncle

Validator questions

I'm trying to operate partial type of my User model as I omit the passwordHash field at instantiation. When I follow the docs I end up with the
select
included in the type, this is from my sveltekit app:
  import { Prisma, type User } from 'prisma/prisma-client'
   const partialUser = Prisma.validator<Prisma.UserDefaultArgs>()({
      select:{ email: true, givenName: true }
   })
   export let nameBlock: typeof partialUser;

Property 'givenName' does not exist on type '{ select: { email: true; givenName: true; }; }'.ts(2339)
Solution
Can you try this code?
import { Prisma } from '@prisma/client'

const partialUser = Prisma.validator<Prisma.UserDefaultArgs>()({
  select: { email: true, givenName: true }
})

// Create a type-safe object using Prisma.UserGetPayload
type PartialUser = Prisma.UserGetPayload<typeof partialUser>

// Example usage in your SvelteKit app
export let nameBlock: PartialUser

You may need regenerate your Prisma client or restart your typescript server in your IDE
Was this page helpful?