Beginner's TypeScript Section 18 exercises
Problem

Passing Type Arguments

For this exercise, we'll be working with the Set data structure from JavaScript.

Here we're creating a set of guitarists and adding Jimi Hendrix and Eric Clapton to it.


const guitarists = new Set();
guitarists.add("Jimi Hendrix");
guitarists.add("Eric Clapton");

We also have th

Loading exercise

Transcript

0:00 Hello. I've changed my t-shirt. Now, we have a problem here which is to do with this set here. We are adding guitarists to this set. We're adding Jimi Hendrix to it and Eric Clapton. This set, by the way, if you've never seen it before, it's nothing to do with TypeScript. This is actually a JavaScript thing. We're expecting that guitarists should contain Jimi Hendrix and Eric Clapton, which they do.

0:23 We're also expecting an error to throw here when you add a non-string to that set. If I remove this, then this should be erroring here, but it's not. For some reason, our set isn't being strictly typed as a set of strings. We've got it here, too, "Should be typed as an array of strings."

0:45 When we get our guitaristsAsArray here, when we call Array.from guitarists, then it should be returning a type which is a string array, but it's not. It's saying it's unknown array. Your challenge is to figure out -- I'll give you a clue, it's on this line -- how to type this set as a set of strings and not just what it is now, which is a set unknown.