DEV Community

Cover image for The benefit of using typescript

Posted on

The benefit of using typescript

Typescript is fairly popular today, as it covers all the features of javascript, but adds static type checks to the language.

Type errors can be tricky to find in Javascript, and in many cases produce unwanted or unexpectd results like this one:

1+"1" = "11"
Enter fullscreen mode Exit fullscreen mode

So far, the benefits of using typescript are evident.

But type errors are by far not the only mistakes we can make. From simple typos, syntax error, undefinded or double defined Variables there is a whole bunch of things you can do wrong.

Javascript uses a "Just-in-time" compiler, that find some errors before it runs the code, like typos and syntax errors, undefined variables etc.. But some errors are detected only when the code is executed, usually by stopping the code unless you did not add some error handling. So, it may happen, that some errors are hidden deep in a code, that is not executed very often.

If you use Typescript, you need to use the TSC compiler to convert .ts to .js. As the compiler reads and translates the code, it could possibly find more errors than a Just-in-Time compiler that reads javascript. Is assume that this is true, as error checks will consume some time, and browsers are highly optimized for speed.

I tried to find a clear definition about the different checks the Javascript-compiler and the Typescript-compiler can do - beside the type checks we know. So, can someone tell, what the benefits of the TSC over the JIT are beside the typechecks? Is code checking in TS really more strict, or are typechecks the only advantage we get?

Discussion (0)