Can You Tell What’s Wrong With This Code?

TypeScript

ES6

TypeScript can! Do you see that little red underline? That’s TypeScript giving us a hint that something has gone very wrong.

You’ve probably figured this one out already— 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 that we can only pass the type string as an argument to our nameToUpperCase() method.

Great! Now instead of having to remember nameToUpperCase() only accepts a string, we can trust TypeScript to remember it. Imagine having to remember thousands, if not tens of thousands of methods, and all the argument types. Impossible!

We still see red though. Why? Because we’re still passing an integer. Let’s pass a string now.

Notice TypeScript gets compiled to JavaScript (it’s just a superset of JavaScript, much like C++ to C)

That’s the big reason why TypeScript and type checking is great.

TypeScript had 10,327,953 downloads in the last month.

Typescript downloads compared to Flow downloads

Let’s explore the TypeScript world. We’ll take a deep dive later, but first, let’s understand what exactly TypeScript is and why it exists.

TypeScript first appeared on 1st of October, 2012. It’s developed by Microsoft; led by Anders Hejlsberg (lead architect of C#) and his team.

TypeScript is completely open sourced on GitHub, so anyone can read the source code and contribute.