Intro to Typescript

Learning your first programming language is difficult. Picking which one to learn next can be even more difficult. Why rock the boat when you are finally feeling successful? If you happened to learn Javascript first, then Typescript, it turns out, is a much less terrifying option.

Typescript is a superset of Javascript and it first came out in 2012 to help combat issues that Microsoft programmers were having when they were trying to scale up their Javascript code base. Typescript allows for optional static types, which allow for more strongly typed code. What does that mean?

// Javascript
let bar = 'foo'; // -> the type of bar is interpreted as a string
const three = 3; // -> the type of three is interpreted as a number
bar = 42; // -> works just fine
// Typescript
let bar: string = 'foo'; // -> the type of bar is set to string
const three: number = 3; // -> the type of three is set to number
bar = 42; // -> Type '42' is not assignable to type 'string'.
let list: number[]; // -> list is set to an(empty) array of numbers

In Javascript, the type of variables are pretty much always interpreted. In Typescript, they can be set and will give an error if you try to change the type. Now this may not look like much in a simple example(and Typescript involves so much more than this), but it’s a start in the right direction. Honestly, the best way to see how useful Typescript can be is to do a tutorial or two, then build an example with it. I recommend checking out an Angular2 example. Two birds, one stone.