I am setting up a TS project for my first time. And I'm curious - I can use and config Babel or just do tsc ..
for transpiling.
What is the main difference between the two?
Babel for transpiling, tsc for typests file generation. By using babel's support for TypeScript, you get the ability to work with existing build pipelines and are more likely to have a faster JS emit time because Babel does not type check your code.
If you need custom transformations, you'll need to use Babel. The good news is that most TypeScript tools allow you to both use TypeScript and then run the code through Babel afterwards, to get the best of both worlds. But this obviously comes with additional complexity in your build-chain.
If you need to use custom transformation, Babel is the best solution. It supports a variety of plugins to optimize your code, while TypeScript only supports its own Transformer API with lesser features.
Babel continues to be used by thousands of companies all over the world. It's integrated into all kinds of frameworks in the JavaScript ecosystem, whether it's React, Next. js, Vue, Ember, Angular, etc.
Main difference is the support for the TypeScript language itself.
You can use tsc
to transpile ES6+ to older versions of the standard, just as you would do with Babel, by basically putting "strict": false
in your tsconfig.json
. Or you can use a type checker like Flow on top of Babel to achieve similar effect to what the TypeScript compiler gives you by default.
AFAIK, tsc
doesn't use Babel - I've seen them produce differently behaving code out of the same source .js file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With