0xedB0...3484

Turn your stories into NFTs

0 Following     0 Follower

My view on TypeScript

TypeScript:name is:verb such:any a:article mistake:noun !:ponctuation


I've worked full time with TypeScript for 6 months and I never got really convinced. Stupid syntax, wrong philosophy, it makes you waste more time than you gain from using it.

Here are a few points if you consider switching to TS:

1. TypeScript will give you a false sense of security, because its whole assumption is that your code is safe once it's type safe. The truth is that around 20% of bugs come from mistyping, and that leave the majority of bugs there in your application.


2. Specifying types is boring. It could have been worth it at a time we had stupid editors, but now, editors like VS Code are really good at guessing variables types, so most of the time they get it right.

When they don't, or when you need to really type some specific object, JSdoc is just perfect for that. The advantage of JSdoc is that it's a comment around your code, it's not directives in your code.


3. TypeScript is time consuming. Yes, so you are all happy that your editor provides you with the nice suggestions with intellisense, and you believe that's thanks to TypeScript, but if you already write clean JS code and sometimes use JSdoc when needed, VScode will do it just as well without having to use TypeScript.

On the other hand, systematically having to specify types costs time and mental efforts. At the end of the day, this typing stuff bores developers out and that's why you end up with lots of :any here and there because at some point, your colleagues were just to tired or too much in a hurry to figure out which type they should have put.

All this type import plumbing eats your days.

I realised I had become a real TypeScript developer when I spent more time fixing stupid type errors and types warning messages to please the TypeScript compiler, than actually writing real code.


4. TypeScript is doing JavaScript the wrong way. The first assumption of TypeScript is that good languages are strictly typed languages. Well, hard luck, JavaScript is a loosely typed language. If you don't like that, please write C#. Loose types is what makes JavaScript flexible. You can write a function in JavaScript that can accept a string, or an integer, or an object, or a function ... if you write abstract code that can be re-used in many places, your function will tend to accept :any-thing.

This is the opposite direction of TypeScript, which, in a way, is much more narrow minded than JavaScript.


So, my opinion is that TypeScript was probably made by MicroSoft because it had failed to impose C#, and it simply onboarded the JavaScript winning boat to pollute it with all the same bad design choices that had turned C# into a failure.

If you cannot fight them, join them.

TypeScript is probably the second worse thing that happened to JavaScript. The first worst thing being classes (JS doesn't need classes. JavaScript has prototypal inheritance).

Conclusion

Finally, if you want to make your code safer, invest your time in writing unit tests instead of spending hours fighting with types.


Some more readings on the topic:

Reactions are currently disabled. They will return soon.

⏪ Previous Story

0xedB0...3484 avatar

Two ways for mankind

From now on, there are roughly two paths for mankind: either we manage to master fusion energy ... or we ...
by 0xedB0...3484

⏩ Next Story

0xedB0...3484 avatar

Clearer versioning

Although StoryPress's smart contracts have already been developed, tested and deployed, StoryPress.info's ...
by 0xedB0...3484