Chapter quiz · Generics

Test what you learned.

8 questions on Generics. Pass 70% to clear the chapter.

← Review chapter lessons

Quiz

TS Generics — Chapter Quiz

Eight questions on generic functions, constraints, classes, and patterns.

0/ 9
  1. Question 1
    1

    What problem do generics solve?

  2. Question 2
    2

    What is the inferred return type of identity('hi')?

    function identity<T>(x: T): T {
      return x;
    }
    
    const r = identity("hi");
    
  3. Question 3
    3

    How do you constrain a generic to "must have a length property"?

  4. Question 4
    4

    Type parameters can have default values like function parameters.

  5. Question 5
    5

    Which of these is a generic interface declaration?

  6. Question 6
    6

    A type that references itself is called a ___ type.

  7. Question 7
    7

    Which of these are valid generic class signatures?

    Select all that apply.

  8. Question 8
    8

    Why might you use multiple type parameters like <K, V>?

Pick an answer — instant feedback as you go.