TypeScript

ES6 is the current version of JavaScript. TypeScript is a superset of ES6,which means all ES6 features are part of TypeScript, but not all TypeScriptfeatures are part of ES6. Consequently, TypeScript must be transpiled into ES5to run in most browsers.

One of TypeScript's primary features is the addition of type information, hencethe name. This type information can help make JavaScript programs morepredictable and easier to reason about.

Types let developers write more explicit "contracts". In other words, things like function signatures are more explicit.

Without TS:

  1. function add(a, b) {
  2. return a + b;
  3. }
  4. add(1, 3); // 4
  5. add(1, '3'); // '13'

With TS:

  1. function add(a: number, b: number) {
  2. return a + b;
  3. }
  4. add(1, 3); // 4
  5. // compiler error before JS is even produced
  6. add(1, '3'); // '13'

原文: https://angular-2-training-book.rangle.io/handout/features/typescript.html