Recall & Review
beginner
What are multiple generic parameters in TypeScript?
They are placeholders for types that allow a function, class, or interface to work with more than one type, making the code flexible and reusable.
Click to reveal answer
beginner
How do you declare a function with two generic parameters in TypeScript?
Use angle brackets with two type variables separated by a comma, like , before the function parameters.
Click to reveal answer
beginner
Example: What does this function do?
function pair(first: T, second: U): [T, U] { return [first, second]; }
It takes two values of any types T and U, and returns a tuple (pair) containing both values in order.
Click to reveal answer
intermediate
Why use multiple generic parameters instead of just one?
Because you might want to work with two or more different types at once, keeping their types separate and flexible.
Click to reveal answer
intermediate
Can generic parameters have constraints when using multiple generics?
Yes, each generic parameter can have its own constraint to limit what types it can accept, improving type safety.
Click to reveal answer
How do you declare a function with two generic types T and U in TypeScript?
✗ Incorrect
The correct syntax uses a comma between generic parameters inside angle brackets: .
What does this function return? function combine(a: T, b: U): [T, U] { return [a, b]; }
✗ Incorrect
It returns a tuple (array) containing the two values with their respective types.
Can each generic parameter have its own constraint in multiple generics?
✗ Incorrect
Each generic parameter can have its own constraint to restrict its type.
Why use multiple generic parameters instead of one?
✗ Incorrect
Multiple generics allow working with different types independently.
Which of these is a valid generic function with two parameters?
✗ Incorrect
Only option C uses the correct syntax with a comma separating generic parameters.
Explain how to declare and use a function with multiple generic parameters in TypeScript.
Think about how you can pass two different types and keep them separate.
You got /4 concepts.
Describe why multiple generic parameters are useful and how constraints can be applied to them.
Consider real-life situations where you want to keep two things different but related.
You got /3 concepts.