Why would anyone use Babel instead of TypeScript's compiler these days?
I think the main conceptual difference is that Babel is a plugin ecosystem while TypeScript has a fixed set of features. But I think it's common for people to not consider the TypeScript compiler because they're not using the TypeScript language.
Reasons to use Babel:
* Babel supports bleeding-edge proposed language features like the pipeline operator, throw expressions, optional chaining, etc.
* Babel lets you run custom transforms like babel-plugin-idx and babel-plugin-rewire.
* Babel gives you more control over exactly which transforms you want to run. In one case, I wanted to disable most transforms, but still had to enable the class transform for interop with CoffeeScript classes. TypeScript would need a custom option for any use case like that.
* Babel supports both Flow and TypeScript.
* Babel is a community project rather than being primarily developed by one company. Microsoft theoretically could make a business decision to stop TypeScript development, but nobody could do that for Flow.
Reasons to use TypeScript:
* From my measurements, TypeScript is quite a bit faster than Babel at compiling ES2017 to ES5. From a quick test, TypeScript took 35 seconds and Babel took 140 seconds when run on my codebase at work.
* TypeScript is probably easier to set up and configure. No individual plugins or presets to install, you just set your compilation target in the config. The TypeScript team has already made the decision about which proposed features (e.g. object rest/spread) are safe to use right now, so there's less decision-making to do in that regard.
* TypeScript is maintained by a full-time team at Microsoft, and there's less risk of the maintainers getting burnt out.
> * From my measurements, TypeScript is quite a bit faster than Babel at compiling ES2017 to ES5. From a quick test, TypeScript took 35 seconds and Babel took 140 seconds when run on my codebase at work.
Hmm, I would of thought it would be the opposite but I guess it depends on the setup?
> * TypeScript is probably easier to set up and configure.
Yeah given it's more of a "language" TS can decide on those defaults although you can just make your own preset for your company/project as well. I think we can fix that too with a default/separate thing but not sure yet.
I've actually been hacking on a faster alternative to babel/tsc for simple use cases: https://github.com/alangpierce/sucrase . It has a built-in benchmark (`yarn run benchmark`) with at least one example of where typescript is about 3x faster. So you could look at that config if you want one example to compare the two.