Bird
0
0

Which of the following is the correct signature for the canActivate method in a NestJS guard?

easy📝 Syntax Q3 of 15
NestJS - Guards
Which of the following is the correct signature for the canActivate method in a NestJS guard?
AcanActivate(): number
BcanActivate(request: Request): string
CcanActivate(response: Response): void
DcanActivate(context: ExecutionContext): boolean | Promise<boolean> | Observable<boolean>
Step-by-Step Solution
Solution:
  1. Step 1: Recall the method signature

    The canActivate method accepts an ExecutionContext and returns boolean or async boolean.
  2. Step 2: Match the correct signature

    canActivate(context: ExecutionContext): boolean | Promise | Observable matches the expected signature with boolean, Promise, or Observable return types.
  3. Final Answer:

    canActivate(context: ExecutionContext): boolean | Promise | Observable -> Option D
  4. Quick Check:

    canActivate signature = boolean or async boolean [OK]
Quick Trick: canActivate returns boolean or async boolean [OK]
Common Mistakes:
  • Returning string or void instead of boolean
  • Wrong parameter type like Request or Response
  • Missing async return types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NestJS Quizzes