TypeScript for ES6
TypeScript is a superset of ES6, which means TypeScript adds to the syntax of ES6 in order to provide the strict typing we covered in Part 1. All of ES6 is valid TypeScript, and means you are able to write your code however you like and still use TypeScript.
That means features like modules, classes, arrow functions, and other ES6 features can be used and TypeScript will convert them into an equivalent ES5/3 syntax. You can use TypeScript as an ES6 transpiler even if you don’t use TypeScript features, because it can still parse your source code and understand how to transpile it.
For Angular, this means you can use just TypeScript instead of another tool like Babel for transpiling ES6. Some features of Babel are opt-in, such as module loading, so with TypeScript you may get those features directly.
TypeScript is a NodeJS module, and can be used from the terminal. When TypeScript transpiles the source, it will inspect the code for any possible errors that can arise from using an incorrect value based on the typing information provided. For example, if you declare
let items:Array =  and try to use it like
items.id = 'abc' it will stop transpiling and show you the error that items is expected to be an array.
Coming up in future posts
- Angular 2 is also written in TypeScript, which means anytime you use an Angular 2 feature TypeScript will know if you are passing the correct types of values.
- TypeScript enhances IDEs since they can inspect the source and understand more about the expectations of code, and suggest to you what values are acceptable.
- Using TypeScript with Angular Part 1: Stronger Typing
- Using TypeScript with Angular Part 3: IDE Support