Passing Type Arguments 7 exercises
Problem

Defaults in Type Parameters

Let's continue from where the previous exercise left off.

We have the createSet function that passes the generic T into a Set:


export const createSet = <T>() => {
return new Set<T>();
};

Like before, the numberSet and stringSet work as expected:


const nu

Loading exercise

Transcript

0:00 This exercise starts where the previous exercise ended, where we have a createSet function, which is passing our generic into our Set here, and this works for number and for string. Now, instead of expecting this one to be unknown -- Set<unknown>, rather -- we're actually expecting it to be Set<string>.

0:21 Your job is to try and work out what the default or how to specify a default in this whole setup so that when we don't pass the type argument here, it gets resolved as string.