Bird
0
0

Which of the following is the correct syntax to define an entity named User in NestJS?

easy📝 Syntax Q3 of 15
NestJS - Database with TypeORM
Which of the following is the correct syntax to define an entity named User in NestJS?
Aexport class User @Entity() {}
B@Entity() export class User {}
C@Entity export class User {}
Dexport @Entity class User {}
Step-by-Step Solution
Solution:
  1. Step 1: Understand decorator placement in TypeScript

    Decorators like @Entity() must be placed immediately before the class declaration.
  2. Step 2: Check syntax correctness

    Only @Entity() export class User {} correctly places the decorator before the class and uses parentheses.
  3. Final Answer:

    @Entity() export class User {} -> Option B
  4. Quick Check:

    Correct entity syntax [OK]
Quick Trick: Decorators go right before the class with parentheses [OK]
Common Mistakes:
  • Placing decorator after class keyword
  • Omitting parentheses on @Entity
  • Incorrect order of export and decorator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes