DEV Community

Discussion on: Moving from JavaScript to TypeScript

Collapse
kostyatretyak profile image
Костя Третяк

Typescript... overall more clutter and things that distract you from your main goal: write code to solve problems.

This can only be said by someone who doesn't actually use TypeScript. Although I agree that code in TypeScript is often much harder to read.

Thread Thread
dvddpl profile image
Davide de Paolis

We use typescript in some of our projects. so this opnionated statement comes from direct experience.
I am not denying that TS is useful, I am stating that it makes code too verbose - and long.

We as devs, have to find a balance between the clarity that comes from typization and the readability of the code itself. When i read code quickly to do a review, or to debug something, i want to be able to quickly read and grasp the underlying logic - TS is too me, too often, simply longer to read.

Thread Thread
lukeshiru profile image
Luke Shiru

The thing is, if you do TS correctly, you don't type that much, you generally just type something when that something can't be inferred. For example this is perfectly valid TS:

const add = (a = 0, b = 0) => a + b;
Enter fullscreen mode Exit fullscreen mode

You don't need to do this at all:

const add = (a: number = 0, b: number = 0): number => a + b;
Enter fullscreen mode Exit fullscreen mode

All that is inferred ... so you only type when the compiler can't infer the type, which usually also means that you as a developer reading that might need that type to understand what the function is taking or what is returning. Is almost like just adding comments when the code is actually hard to follow.

Thread Thread
dvddpl profile image
Davide de Paolis

Agree. This is what I mean. We don't have to explicitly type everything. Most of the time devs do that though, making the code less readable. (of course that is a problem of how ts is used rather than of ts itself).
What I find annoying is just when you are passing around objects and starting out with my implementation and ts can't really infere much yet and start nagging about missing or invalid props. Then instead of going on with the implementation, you have to fix typing issues..