-
QuestionMy model is defined as follows: model User {
id Int @id @default(autoincrement())
name String @unique
password String
regionId Int
role Role
addtime DateTime
regUid Int?
lock Boolean
} When querying using findMany, the return value is defined as follows: const r = await prisma.user.findMany({ omit: { password: true } }) As you can see, there is no password field. I'm trying to write a general utility method whose return value is deduced as follows: async function testQuery<M, A extends Prisma.Args<M, 'findMany'>>(model: M, queryParams: A) {
return await (model as any).findMany({ ...queryParams }) as Result<M, A, 'findMany'>
}
const r = await testQuery(usePrisma().user, { omit: { password: true } }) As you can see, the password field was not successfully excluded. Please help, how to define the parameters and return values of testQuery so that parameter exclusion can be handled correctly, thank you. How to reproduce (optional)No response Expected behavior (optional)No response Information about Prisma Schema, Client Queries and Environment (optional)generator client {
provider = "prisma-client-js"
previewFeatures = ["omitApi"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
shadowDatabaseUrl = env("SHADOW_DATABASE_URL")
}
enum Role {
ADMIN
USER
}
model User {
id Int @id @default(autoincrement())
name String @unique
password String
regionId Int
role Role
addtime DateTime
regUid Int?
lock Boolean
}
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Update, setting the select field is valid: const r = await testQuery(usePrisma().user, { select: { id: true, name: true } }) In other words, it may be that the new omit has not been adapted yet. |
Beta Was this translation helpful? Give feedback.
-
Hi @Cat7373 👋 Thank you for raising this question. We are trying to reproduce this but are running into a type error for |
Beta Was this translation helpful? Give feedback.
-
First, I can confirm the issue on our side. The problem seems to be TS infering type of 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'>
} |
Beta Was this translation helpful? Give feedback.
-
This discussion has been turned into a bug issue: #23990 |
Beta Was this translation helpful? Give feedback.
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 aconst
modifier toA
in yourtestQuery
definition, like this: