TypeScript — JavaScript with superpowers II

Enums (enumerations) allow you to group values together with friendlier names. Imagine you had a list of names.

Here’s how you would structure the enum:

You can grab the values from the enum like so:

TypeScript — JavaScript with superpowers

Javascript is cool. But do you know what’s even more cool?


Can you tell what’s wrong with this code?

TypeScript (left) and ES6 (right)

TypeScript can — see that little red underline? That’s Typescript giving us a hint something is horribly gone wrong.

You probably figured this one out (good job) — toUpperCase() is a type of String method. We’re passing an integer as the argument, thus we can’t call toUpperCase() on an integer.

Let’s fix it by stating we can only pass the type String as an argument to our nameToUpperCase() method.

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now