Typescript type is not being inferred from Prisma query #21381
Replies: 3 comments 1 reply
-
Hello @pavanputhra 👋 If you have invoked Can you try this snippet and check if the IDE throws an error for you? import { PrismaClient, User } from "@prisma/client";
const prisma = new PrismaClient({
log: ["query"],
});
async function main() {
await findUserByEmail("test@prisma.io");
}
export async function findUserByEmail(email: string): Promise<User | null> {
return prisma.user.findUnique({
where: {
email,
},
});
}
main()
.catch((e) => {
throw e;
})
.finally(async () => {
await prisma.$disconnect();
}); |
Beta Was this translation helpful? Give feedback.
-
How to counter for Enums? |
Beta Was this translation helpful? Give feedback.
-
I figured out why type inference was not working. It is because of how i imported it. Here is how I imported it.
Why did I import that way instead of regular
|
Beta Was this translation helpful? Give feedback.
-
Question
I have following schema in Prisma
When I write the following typescript code, I expect the return type to be correctly inferred, but the
user
variable is beeing infered asany
type. Is it how prisma works, or am I doing something wrong?Btw, I am using Prisma version
5.2.0
I have used the
npx prisma generate
. It generates proper type inference for input parameters. For example, if wrong field is set in where clause editor shows error. But only return value is inferred asPromise<any>
How to reproduce (optional)
Expected behavior (optional)
IDE should infer that return time is
Promse<SomeUser>
Information about Prisma Schema, Client Queries and Environment (optional)
// Add your schema.prisma
// Add any relevant Prisma Client queries here
OS: macOS
Database: PostgreSQL
Node.js version: v18
Prisma version: 5.2.0
Beta Was this translation helpful? Give feedback.
All reactions