type-safely wrapping `findMany`
I am trying to wrap the
findMany
function in a separate function.
Can someone help me to get this right:
So my trail of thought was to make it similar to a client extension (which is not what I want. I would like the function presented to be correctly typed) yet I do not have the this
property to work with. So I ended using Prisma.Args
to describe the shape of input args that I want and Prisma.Exact
to narrow A
down to Prisma.Args<T, 'findMany'>
. This leads to args
being rejected as valid for prisma.assignment.findMany
So I get this error if I use Prisma.Exact
for args
As a 2nd problem, I can't get the return type right. the return prisma.assignment...
statement has red squiqqly lines with TS complaining:
So apparently I get everything wrong and I can't figure out how this should work. Does anyone know how to make it so that my personal wrapper exactly type-safely mirrors the type/shape/behavior of prisma.assignment.findMany
?6 Replies
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into
#ask-ai
for a quick spin!Does anyone have an idea about this? I am still wondering how to do it 😄
Hi @ptrxyz
Can you try this code?
This approach should resolve both of the issues you mentioned:
1. It should accept the args parameter without type errors.
2. The return type should be correctly inferred based on the input arguments.
I will give it a try in a few!
thanks so far
let me see if it works
you can use it like this
yes, this seems to be what i need. one thing about the args, i had to change SelectSubset to Prisma.Exact to make it work, but it does what it should now!
Thanks a bunch!