D
D
Dolerum2019-10-11 08:40:04
typescript
Dolerum, 2019-10-11 08:40:04

Compiler for typescript in webpack for react project, explain the difference?

Why do projects for react often use ts-loader and not babel-loader? Wouldn't it be easier to have babel parse everything together?
What are these preferences?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
ned4ded, 2019-10-11
@Dolerum

Good afternoon.
Answering your question - "Why do projects for react often use ts-loader, and not babel-loader?" - they are interchangeable, because both are transpilers, only the inputs differ.
Answering - "Isn't it easier for babel to parse everything together?" - no, it's not simpler, Babel does not perform type checkingand you still need to install tsc and, accordingly, configure webpack to use tsc for type checking before building code through babel. Despite some overlapping features, typescript is more of a different programming language, while babel is based on modern versions of ecmascripta. In other words, js before being compiled with babel can be run in modern or future browsers, while typescript can never be run directly in a js environment without compilation. And this begs the question, why use babel to compile typescript syntax into js without type checking and other tsc features when typescript has its own transpiler? I propose to answer this question for you.
Here is a link to implemented features in different environments.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question