Current section: TypeScript 59 exercises
Problem

Narrow Types

Loading exercise

Transcript

00:00 So we've made things much better, so we don't accidentally pass a string or whatever to these different things. But we only have some very specific operators here. You can only do plus, minus, multiply, divide based on our operations that we can do up here.

00:14 And it would be nice if we only allow those, so we would get an error if we tried to do something like this, rather than having to run the application to see that that is not going to work. So, your job is to make the operator more narrowly typed. So right now, it's a broad type.

00:32 It means we can accept all sorts of different kinds of inputs. You could do, like, any sort of string here. But we want to narrow down the type to just some specific string. So it can be plus, minus, multiply, or divide, and it can't be anything else. So your job is to do that in the most efficient way possible. Have a good time.