Advanced Generics 9 exercises

Spotting Useless Generics

Here we have a function called returnBothOfWhatIPassIn with type arguments T1 and T2. It takes in a params of a: T1 and b: T2 that is then returned as a tuple:

As seen in the test, when calling returnBothOfWhatIPassIn with {a: "a", b: 1}, we should get back string and number:

Loading exercise


0:00 In this exercise, we have a function called returnBothOfWhatIPassIn. What we've got here is T1 and T2, the params: { a: T1; b: T2 }, and we're returning them in a tuple, basically.

0:13 What we've got here is they're being inferred as string and number, and we're getting back string and number in this tuple slot. We don't care about being too strict here. We're not looking for the literal "a" or the literal 1 here. We just want string and number.

0:29 You notice there's no errors in this file. The tests are all passing. Everything's great, but we can remove one of the generic parameters here. It seems a little bit clumsy the way that we've done it, and one of these generics is a little bit useless and we can condense them down.

0:49 That's your challenge, is to try to find a way to refactor this file so that we don't have one of these generic parameters.