TypeScript Analogy

Please note: This article is only available in English.
A good analogy that helps to understand when to choose TS over plain JS.

At the moment I am conducting many interviews. Some of these interviews involve a small coding challenge in which candidates may chose a problem to solve. Not few pick a frontend case, where a small web app has to be created. Most of the time JS is picked, which gives me the simple question: Why not choose TypeScript?

Besides some people not being so familiar with TypeScript (everyone has at least heard about it, but apparently not everyone has had the chance to use it), some claim that TypeScript would not be a good fit for their working mode. Others claim that the problem was too small and had to be delivered too quickly for TypeScript to fit in ideally. In this article I will try to create an analogy to reflect when using plain JS is alright and when TS should be preferred.

I consider TypeScript to be like shoes. JavaScript is barefoot. Depending on the strictness in the TypeScript configuration the shoes can either be like climbing shoes where each toe is directly exposed (just giving some grip, but leaving a lot of freedom) or ski boots (quite stiff, however, giving maximum robustness to sustain even heavy loads). This analogy also fits meaning that TypeScript can never "run" alone, it will always require transpilation to JS. TypeScript is a superset of JavaScript - a shell to improve robustness and make dynamic team collaboration on projects easier.

So how does this analogy help us in categorizing projects with respect to the anticipated usage of TS? If you wake up in the morning and go to your bath room - do you make the effort of putting on shoes? Maybe not. Maybe inside your flat you (at least sometimes) do not wear shoes - and if so: then just some house shoes / slippers. However, once you go outside you will definitely wear some shoes. Of course, sometimes you may be outside without shoes. It is summer and you are on the beach or having a picnic on the grass. But these are not standard conditions and they certainly not in a professional environment.

So always when it counts we will wear some shoes. We even wear shoes when we go to get some groceries. We would also wear shoes when we just empty our inbox. Of course, it is sometimes annoying to put some shoes on. It will definitely take a little bit more time to have the shoes properly mounted, especially if we did not have much practice in tying shoes (e.g., in our youth). The same obviously applies to TypeScript. The claim that some people make ("I am just faster with plain JS") is merely an indicator that they are not trained with TypeScript. It is not a constant statement that will always be true (for every project or person).

Coming back to the original problem we should try to always use TypeScript. It protects us in many waays and can also save us a lot of time.

Created .


Sharing is caring!