What are the main differences between Babel and TypeScript

DevWL picture DevWL · May 25, 2016 · Viewed 29.5k times · Source

I know that TypeScript was used to write Angular2, which probably makes it a better choice for someone who wants to get into Angular2, but when I look at Babel it looks very much like TypeScript.

I noticed that many well known companies stick to Babel.

Some questions:

  1. What advantages do they have over each other?
  2. Which make them better or worse choice for the project/developer?
  3. What are the major differences between them and what make them unique?

Answer

Marty picture Marty · May 25, 2016

TypeScript is a superset of JavaScript that compiles down into plain JavaScript (ES3+). The main goal of TypeScript is to enable developers to leverage excellent static typing capabilities. It is suitable for large applications that would benefit from features like:

  • Type annotations & type inference.
  • Generics.
  • Interfaces, enums, namespaces, modules and classes (the latter two available in ES6).
  • Safe refactoring.

As far as I am aware, Babel simply "transpiles" newer ECMAScript features down into a format that is supported by older ECMAScript environments. It is suitable for developers who want to write plain JavaScript using newer language features.