My feeling toward TypeScript

Note: nothing I’v writing here is relevant if you are programming in a structured, well-defined, immutable ecosystem. And my thoughts are not applied to reusable well-defined code components. Only to the ordinary messy components we usually create for one-time app usage.


Lately, there is a shift at the place I’m working for towards TS. And though I have used TS in the past, this time I found myself as an opposition. getting only answers such as “everyone likes it” or “this is where the industry is aiming”.

As uncle Bob had showed so well, code needs to be clean: readable, more readable, and then readable even more. This is why we don’t have comments in the code. This is why we use meaningful names. This is why we refactor constantly. This is why we definitely don’t pass more than three variables to any function (or to React components). The code is supposed to be KISS. you are supposed to be able to read it as a newspaper paradigm. Yup, even FE code.

And if we find ourselves in a need to pass more than three variables, we identify their common structure, create a new object, defining a well-defined object that describes itself. A simple and readable ideal world.

Unfortunately, most languages are strongly typed, they need to allocate memory, which is why they must add noise into the code by defining the variable type. So they made the noise as natural and unseen as possible. They structured the language the way the noise will come as smoothly as possible.

But in most JS app the story is different.

The FE developer use objects as provided from the server, without need or even not wanting to synchronize the full object on each change. By definition, FED’s receive a unmutable object, and therefor allow themself to mute it on every foreach/map iteration. And from other unfortunate reason, in most cases, we use props as if there is no common structure. We definitely don’t create a describable immutable object with a constructor and validation for each component. Worse than all, TS is not as elegant as typing in Java, it is not clean. It adds plenty of noise to the code.

Now remembering the most important thing is to make the code KISS, it seems as if we have forgotten that the browser/JS is not strongly typed, we can not and don’t need or use the variable types. As far as I know, V8 removes them before running.

Where it leaves us? We have unstructured, un-synchronized, longer, and more complicated code with just the ES debugging. Can TS do good? Definitely, but for that, we need to look at JS as a structured language, refactor it constantly, and not use components as a collection of props.

So while I remove some rust from my TS capabilities, I wonder: Have I got it wrong? Maybe. But this is the reason I have written this post, to organize my thought towards TS.