Bird
0
0

Given this Prisma query in a NestJS service:

medium📝 Predict Output Q4 of 15
NestJS - Database with Prisma
Given this Prisma query in a NestJS service:
const user = await prisma.user.findUnique({ where: { id: 1 } });

What type will user have?
AUser[]
Bany
CUser | null
Dvoid
Step-by-Step Solution
Solution:
  1. Step 1: Understand findUnique return type

    Prisma's findUnique returns a single record or null if not found.
  2. Step 2: Identify the correct TypeScript type

    So the type is the model type (User) or null.
  3. Final Answer:

    User | null -> Option C
  4. Quick Check:

    findUnique returns single or null [OK]
Quick Trick: findUnique returns one record or null [OK]
Common Mistakes:
  • Assuming it returns an array
  • Using any type instead of typed model
  • Thinking it returns void

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes