Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TS transpiling: babel vs tsc

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?

like image 620
Tomas Eglinskas Avatar asked Jun 02 '18 19:06

Tomas Eglinskas


People also ask

Does TSC use Babel?

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.

Do I need Babel with ts loader?

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.

Is Babel needed 2022?

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.

Is Babel still relevant?

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.


1 Answers

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.

like image 82
MayaLekova Avatar answered Sep 27 '22 21:09

MayaLekova