Skip to content

How to exclude fields from method return value based on query parameters? #23947

Closed Locked Answered by SevInf
Cat7373 asked this question in Q&A
Discussion options

You must be logged in to vote

First, I can confirm the issue on our side. The problem seems to be TS infering type of A to be broader that it actually is. Second, I have a workaround for you until the problem is fixed from our side. You need to add a const modifier to A in your testQuery definition, like this:

async function testQuery<M, const A extends Prisma.Args<M, 'findMany'>>(model: M, queryParams: A) {
  return (await (model as any).findMany({ ...queryParams })) as Prisma.Result<M, A, 'findMany'>
}

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by Cat7373
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants