Bird
0
0

Which of the following is the correct syntax to declare a generic Angular service class?

easy📝 Syntax Q12 of 15
Angular - TypeScript in Angular
Which of the following is the correct syntax to declare a generic Angular service class?
Aexport class DataService<T> { }
Bexport class DataService<T extends> { }
Cexport class DataService<T>() { }
Dexport class DataService<T> => { }
Step-by-Step Solution
Solution:
  1. Step 1: Recall the syntax for generic class declaration in TypeScript

    The correct syntax uses angle brackets after the class name with a type parameter, like class ClassName<T>.
  2. Step 2: Match the syntax to Angular service class

    export class DataService { } correctly shows export class DataService<T> { }, which is valid for a generic service.
  3. Final Answer:

    export class DataService<T> { } -> Option A
  4. Quick Check:

    Generic class syntax = class Name<T> [OK]
Quick Trick: Generic classes use right after the class name [OK]
Common Mistakes:
  • Adding parentheses after
  • Using 'extends' without a type
  • Using arrow functions for class declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes