paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
687 stars 55 forks source link

PrismaSelect - `Record<string, unknown> ` instead of `any` #316

Open baptistemarchand opened 12 months ago

baptistemarchand commented 12 months ago

Hi,

It's easier to explain with an example :

  const select = new PrismaSelect(info).value
  // `foo` does not exist in my model so I want to have a TypeScript error here
  await prisma.user.findUnique({where: {id: '123', foo: 42}, ...select})

In the above code I don't get an error, even though the field foo does not exist in my model. That's because select is typed as any, so the spread of ...select makes the whole object any. If I change the first line to :

const select: Record<string, unknown> = new PrismaSelect(info).value

I get the error on foo as expected. So I suggest that new PrismaSelect(info).value should return Record<string, unknown> by default.