This lesson will walk through what TypeScript is, the benefits it offers, and how to install it. In the next lesson we'll practice TypeScript independently, before adding it into Angular.
TypeScript is a free, open-source programming language that runs on any operating system. It was developed and released by Microsoft in 2012. Angular opted to adopt TypeScript in Angular 2.0, released in September 2016. Both Microsoft and Angular continue to support it.
TypeScript is also a compiled language. If you’ve taken our Java or C# courses, this term is likely familiar. If you haven't, it's likely new.
Compiled languages are languages whose source code must be "translated” before it can run. The developer writes the source code, then something called a compiler translates it into code the client (a browser, in our case) can understand.
TypeScript uses data types to catch errors before they manifest. This can save us tons of time tracking down bugs and other issues. (We'll see exactly what this looks like in the next lesson.)
Victor Savkin, a member of Angular's core team, further explains why they chose TypeScript for Angular 2 in his blog post "Angular 2: Why TypeScript?".
We need to install two packages to begin working in TypeScript:
We can install TypeScript globally via npm with the following command:
$ npm install typescript -g
Then, we'll confirm the installation was successful by running:
$ tsc -v
We should see something like this in response:
$ Version 2.1.4
Your version number doesn't have to match this one exactly, receiving any version number confirms TypeScript has been successfully installed.
This is technically optional, but we absolutely cannot recommend it enough. This assists Atom in recognizing and properly highlighting TypeScript code, making it much easier to read.
We’ll run the following command to install
$ apm install atom-typescript
We'll need to restart Atom for changes to take place.
apm stands for Atom Package Manager. Like npm, this is a package manager for Atom add-ons. If you have Atom installed, you should already have apm too! For more information, check out Atom's apm documentation.
apm: Atom Package Manager, apm is included in npm; it is used to optimize installation and maintenance of Atom packages.