Prisma generates TypeScript types from your database schema. This means your code editor and compiler can warn you if you use wrong types before running the app. This reduces bugs and improves developer confidence.
const user = await prisma.user.findUnique({ where: { id: 1 } }); const age: number = user.name;
TypeScript checks types during development and compilation. Assigning a string to a number variable causes a compile-time error, preventing the code from running until fixed.
The email field is a string in the database schema. Prisma enforces this type, so only a string value is accepted. Other types cause TypeScript errors.
const posts = await prisma.post.findMany({ where: { published: 'yes' } });
The 'published' field is a boolean in the schema. Passing a string like 'yes' causes a type mismatch error in TypeScript.
const user = await prisma.user.findUnique({ where: { id: 5 } });
The findUnique method returns the matching record or null if none is found. Prisma types reflect this by using a union type User | null.