Function Overloads 8 exercises
Problem

What is a Function Overload?

For this exercise we have a function called returnWhatIPassIn:


const returnWhatIPassIn = (t: unknown) => { return t; };

The function should return the type of the thing that we are passing in.

As seen in the tests, we want to get back number when passing in 1 and string

Loading exercise

Transcript

0:00 For this exercise, we have a function called returnWhatIPassIn. All we need to do is return the type of the thing that we're passing in here. Currently, one is typed as unknown and matt is also typed as unknown because t here is typed as unknown. We've done this before, but with generics. This time, I want you to do with function overloads.

0:20 You are going to see that the resulting function is not as good, not as complete a solution as the generic one. All I need you to care about is these two cases. Don't have to care about the general case or handling every single case like twos, Pococks, or whatever. Just these two cases. You'll see that function overloads provides quite a nice API for it. Good luck.