19/12/2024
My Opinions On TypeScript
Reading Time: 3 minute
TL;DR: I don't get the necessity of TypeScript and why anyone would need to use it, especially for the personal projects. But it's quite amusing to define types anyway.
I've heard a lot how defining types makes JavaScript better. Quite honestly, I stayed far away from that hype for a long time, because I was never sure why would I even need to define types while writing in JavaScript.
Well, now I've fallen too against the TypeScript hype within Node developers and tried it out to see what kind of "epic" thing it is by my own eyes. The app that you're reading this article on, which named Wordimus, has been developed using entirely TypeScript. Here are my thoughts:
Firstly, I never saw anyone who has been obliget to face off with some type issues while writing in JavaScript. That was the main reason why I never looked at TypeScript. Finally I used it too and found it very useful when I want more problems, not programms.
Maybe it can be useful while writing libraries or frameworks (I have never written one though), but many of the developers are developing applications mostly. It's nice that TypeScript has a better error handling but it's not enough to like it I think.
Actually I found it too overrated and therefore I don't think to use it again at least for personal projects if I won't be compeled to use it again because of some libraries like "drizzle" or framework like "hono". I think I will be compeled to use it again anyway, because the entire JavaScript world comes through to TypeScript, but it won't be willingfully for me.
Let's get started the incomprehensible points of mine about TypeScript.
Actually there is no type safety in it and no need to be though. If I can define the <any> type wherever I want and it just works well, what's the point of the type safety that TypeScript provides? Herewith the whole script becomes just JavaScript with dot-ts files.
The other point is, why would it even need to be type safe? If TypeScript is just a developing dependency and it's going to be compiled to raw JavaScript anyway, what's the point of defining types? It just makes harder the developing process.
The necessity of defining types is making easier the job of the compiler. Otherwise, the interpreter should find the types of variables by itself and it consumes more CPU resources. In the present time, the costs of computer hardwares are not so high to care about hard-optimizing of applications like the old times. Also we are developing just web applications, not low level softwares like drivers or operating systems.
Developers say that it's useful when working as a team, but I think, naming the variables as clearly as possible should be enough to understand their types. If you see a variable named "isActive", you can understand that it has the <boolean> type. It should be true or false, yes or no, nothing else. Because if it was anything else, it would be really weird. For another example, everyone can understand when they see a variable named "id", it's very clear that it's type must be a <number> (if you're not taking it from Params).
It makes me sad to think that all the pain I suffer while writing in TypeScript is for nothing. TypeScript is just not worth it. Because if I would write in JavaScript only, probably I wouldn't face type errors and my scripts wouldn't need to be compiled to JavaScript unnecessarily. It's pointless for me to add one more stage to solve such basic potential issues.
I wouldn't have a problem with TypeScript, if:
1- TypeScript was compiled directly instead of being an additional layer on top of JavaScript and the interpreter.
2- I knew that, while writing in JavaScript, I would face exactly the same problems that TypeScript claims to solve.
Even so, I found TypeScript very amusing to write in because it makes me feel like I'm writing some kind of lower-level language. If I'm going to mess around with types, I hope it's going to be worth it. Maybe I shall try GO on server instead of TypeScript, if I want a real lower-level language.
I don't know how it's going with other Node.js frameworks but honestly, TypeScript with Express is such a mess. Even if one day I decide to use TypeScript again (probably I will), I absolutely won't use it with Express.