Learning TypeScript 2.x
上QQ阅读APP看书,第一时间看更新

The line between TypeScript and JavaScript

One of the most important things that you are going to need to master to become a good TypeScript programmer is to be able to understand where TypeScript ends and JavaScript begins. It is very important to be able to understand what happens with our TypeScript code at three important phases:

  • Design time: This takes place when we are writing our TypeScript code and designing our application.
  • Compilation time: This takes place when we compile our TypeScript into JavaScript code (some compilation errors may take place). Compilation time has subphases, such as parsing the TypeScript code, creating an abstract syntax tree (ATS), and emitting JavaScript code.
  • Execution time (also known as runtime): This takes place when we execute the output JavaScript code generated by the TypeScript compiler.

The TypeScript types are declared or inferred at design time and used during compilation time, but they are not available at execution time because they are not part of JavaScript.

In this chapter, we are going to learn about many of the TypeScript type system features. If you are familiar with JavaScript, you will notice the differences straight away but, if you are not familiar with JavaScript, I would recommend examining the generated JavaScript output after compiling the code samples included in this chapter. Over time, you will slowly earn the experience required to have a clear vision of the line between TypeScript and JavaScript.

Please refer to Chapter 6, Understanding the Runtime, to learn more about the execution time phase (JavaScript).