TS vs JS: A rant

Rakesh GuptaRakesh Gupta
3 min read

If you are working in software and not living under a rock then we must have come across people ranting on TS vs JS. You don't need to be a web developer or a frontend developer for this. because JS/TS is just everywhere.

Basics first: TS is an extension over JS. which is it takes JS and adds things like types, interfaces (types vs interfaces is coming soon ☺️) and lots of other things.

and what do we get: Better error catching (sometimes), really good intellisense and some extra code to deal with.

It allows type gymnastics too. like a separate language altogether with its own primitives and operations.

so that developers can write the code twice, types and the business logic.

then why some people call it to be linter or just an extension.

I have an plausible answer: it does not extend MUCH over JS. If all you are getting is types (which is sometime automatically inferred and sometimes you to write on your own) then I would too hesitate to call it a separate language.

You will have to switch to JS land to write business logic and then hover over a variable or look for red lines through the TS land.

Second big reason is that it does not change the control flow. I can provide better syntax like enums (which is converted to objects) or while writing classes in JS but at the end, we think in terms of JS.

see, it did not change the flow. I am ready to call TS a language if it would provide the type, by default like

and then provide a warning if I do not handle the error. because then, there will be a difference in the expected flow wrt JS.

Honorable mention: in some cases in Nextjs, the code might show a type error and the server would be running just fine. It would check the time when you build the app and then it would throw an error.

I would still use TS because:

  • better intellisense. any time.

  • Absolutely useful when developing packages. It just saves the day when the package you are using provides good types.

  • Since TS has to hold the context of entire code base, it is useful to detect the changes in dependent modules. like you change in one file then there is an error in other file downstream

  • Intellisense is more than enough in most of the cases. Please do not resort to type mathematics. Look I created a type from operating upon 20 types.

Some type extraction or modification is required and we should have respect and space for that. but please don't overdo it.

Parting Thoughts

Please feel free to comment your experience or opinions on what you think of TS vs JS.

Let's keep the debate going.

0
Subscribe to my newsletter

Read articles from Rakesh Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rakesh Gupta
Rakesh Gupta

Dumping random thoughts.