Intro to Generics 9 exercises

Approaches for Typing Object Parameters

Consider this implementation of returnBothOfWhatIPassIn:

const returnBothOfWhatIPassIn = (params: { a: unknown; b: unknown }) => {
return {
first: params.a,
second: params.b,

This time the function takes in a params object that includes a and b.


Loading exercise


0:00 We have another function here called returnBothOfWhatIPassIn, where we're taking this time as a params object, where you need to pass in an object where A is A and B is B. It's expecting to infer just exactly the same as the previous exercise where you have first as string and second as number.

0:19 A is being passed to first and B is being passed to second. Your job is to work out how to type this using generic syntax.