Recall & Review
beginner
What is a generic arrow function in TypeScript?
A generic arrow function is a function written with arrow syntax that uses type parameters to work with different data types while keeping type safety.
Click to reveal answer
beginner
How do you declare a generic arrow function with one type parameter <T>?
You write the function with <T> before the parameters, like: <br><code>const func = <T>(arg: T): T => arg;</code>Click to reveal answer
intermediate
Why use generic arrow functions instead of regular functions?
Generic arrow functions provide concise syntax and allow type flexibility with less code, making them easy to read and maintain.
Click to reveal answer
beginner
What does this generic arrow function do?<br><code>const identity = <T>(value: T): T => value;</code>It returns the same value it receives, keeping the type of the input and output the same.
Click to reveal answer
intermediate
Can generic arrow functions have multiple type parameters? Give an example.
Yes, for example:<br><code>const pair = <T, U>(first: T, second: U): [T, U] => [first, second];</code>Click to reveal answer
How do you start declaring a generic arrow function with type parameter T?
✗ Incorrect
Generic arrow functions use before the parameters to declare the type parameter.
What does the generic arrow function <T>(arg: T): T => arg; do?
✗ Incorrect
It returns the input argument without changing its type.
Can generic arrow functions have more than one type parameter?
✗ Incorrect
Generic arrow functions can have multiple type parameters separated by commas.
Which of these is a valid generic arrow function syntax?
✗ Incorrect
Option D correctly places before the parameters and uses arrow syntax.
What is the main benefit of using generic arrow functions?
✗ Incorrect
Generic arrow functions combine flexibility and type safety with short syntax.
Explain how to write a generic arrow function that returns the input value unchanged.
Think about how to declare <T> and use it in parameters and return type.
You got /4 concepts.
Describe the advantages of using generic arrow functions in TypeScript.
Consider why generics and arrow functions are useful together.
You got /4 concepts.