JavaScript vs TypeScript

I have previously done web-based stuff with JavaScript before, after hearing about TypeScript I have thought that I will test that instead. What are the advantages and disadvantages of using TypeScript instead of JavaScript? In other words, is TypeScript really worth it?
1 answer

TS is a superset of JS with the difference that browsers don’t know how to run TS code, so you need a compiler to transfer the TS code to regular JS. This means that looking from the bundled code, both React JS and React TS bundle the same JS code, hence, no difference in the end.

TS is an object-oriented programming language (JS is a scripting language). Some additional things that TS gives support for modules and it has interfaces (JS doesn’t have interfaces) and types to describe data being used. TS also supports static typing, meaning it permits checking type accuracy at compile time. It highlights the compilation error at the time of the development, so you easily and early detect errors (fewer runtime errors which can be awful with JS).

The coins can be the learning curve depending on your previous experience & also that the compilation time can take some extra time since the source code building has to go through another layer of transpiring.

So, yeah TS is worth it if you have some previous experience in object-oriented programming (or are willing to learn) and have a bigger coding project, but for smaller projects, JS is ideal.

Comments

I have both used javascript and typescript in the past, where I used much more JS than TS.
In my oppinion, the advantage of Typescript is that it provides typing, which doesn't exist in JS.
But I need to correct you in one statement. Javascript is, like Typescript, an object oriented programming language supporting many features OOP-Languages provide, like inherance.

Thomas Stoiber - Mon, 12/20/2021 - 15:51 :::

Thank you for the comprehensive comparison. Although I am often apprehensive to add dependencies to a project I found that Typescript provides a lot of value for relatively little risk of causing additional problems. When a package manager like npm or yarn is already used it is also quite simple to replicate the build environment.

Stefan Puntigam - Tue, 12/21/2021 - 20:25 :::

Thanks ! As this post makes the decision between those two frameworks way easier! I was not working with any of them so far, but now i have an idea of what I might use.

Moritz Ruoff Holzer - Wed, 12/22/2021 - 07:33 :::