DEV Community

The problem with TypeScript and its practices

idleman on March 16, 2023

Most of you probably believe TypeScript is best practices these days. It has some advantages, but also disadvantages. Here are some myths and probl...
Collapse
 
brense profile image
Rense Bakker

The research you linked doesnt appear to conclude what you are concluding from it.

Our Findings therefore indicate that using TypeScript and adhering to its type safety has benefits, but not the straightforward advantage of directly reducing bugs.

This is true. Type safety does not directly reduce bugs. It just catches some bugs at compiletime instead of runtime. A lot of the repos they tested use other testing strategies to catch runtime bugs. They also discuss this in their discussion a few reasons why their research could be wrong about this :P

They say exactly the opposite about bug resolution time from what you claim:

Contrary to expectations, only a single one of our bug-related hypotheses could be accepted, namely that a decreased usage of the any type is correlated with a faster bug resolution time in TypeScript apps. In comparison to JavaScript apps.

And in their discussion part, they discuss atleast one other study who found that Typescript DOES decrease the number of bugs. So one could just as easily link to that research and claim the opposite of what you are saying...

Your problem #1: I dont follow your reasoning... You dont want to use named exports? Then dont... You can simply turn it off in your eslint. Your code completion is going to suck, but whatever floats your boat I guess 🤷

Your problem #2: Why would you want to fetch ts files over a network? You compile typescript to javascript... How imports are handled in the compiled js depends on the module resolution you specify in your tsconfig: typescriptlang.org/docs/handbook/e... you can control nearly every aspect of how your ts code is compiled into js, here are all the options: typescriptlang.org/tsconfig

Your problem #3 I disagree with completely. Typescript is powerful because it does type inference, MS spent a shitload of time making sure it has very strong type inference. They encourages you to NOT over-use typing, but rely on type inference whenever possible.

Collapse
 
idleman profile image
idleman • Edited
  1. Everything I claim has support in the research, everything. If you don't agree so is it unfortunate, but your words have no weight compared to that research paper.

  2. Regarding others research papers that claim the opposite:

PS. I know it exists other studies that say the opposite, but as noted in the research paper as well, those studies are either focus only on a few projects or library code. This is different than what most of us do in our daily life. Most of us code applications, not libraries.

I am free to change my mind, but you need to show me a research paper that have:

  • Conducted tests on more than 600 open source projects.
  • All projects should be similar, popularity and activity.
  • All projects are application-based.
  • The people behind research team have no connection to Microsoft or any organization that would benefit from TypeScript becoming more popular.
  1. Named exports is bad because it increase coupling and it my friend have proven to be bad. Why do you think we have variables? Functions? Modules? Every single thing of those are connected to less coupling. And do I actually need to tell you that you don't need to tell a more senior developer than you what she or he cannot do? Answer: You don´t.

  2. You want to avoid path traversal and you do it by providing specific import/dependency specifiers. If you don´t understand why it is bad thing with the explanation I gave in the post so is there nothing I can say to help you, unfortunately.

  3. So you would say the general recommendation in the TypeScript community is not to add type-annotations and instead let the TypeScript compiler figure it out? I gotta say, you have no clue what you are talking about then. If it was the goal, would TypeScript team remove the "strict" mode immediately and just give a warning the code complexity is so high so it cannot understand what type some value has.

Collapse
 
brense profile image
Rense Bakker

I quoted literal phrases from the research that YOU shared. They are not compatible with the claims that you make. Ergo, you are just here to troll. I would be impressed, except this particular troll topic has already been visited by so many other trolls, its kinda sad you couldn't come up with something new.

Thread Thread
 
idleman profile image
idleman • Edited

I claim TypeScript have equal or more bugs than JavaScript code. And it is the result from the research:

TypeScript applications have a higher bug fix commit ratio than JavaScript applications, i.e., are more or equally prone to bugs.

I don't claim TypeScript don´t have benefits, even if you code in assembler it has benefits. I claim TypeScript do not make your code having less bugs. THAT IS THE CLAIM!

Thread Thread
 
lionelrowe profile image
lionel-rowe

Correlation doesn't equal causation, though. There could be any number of reasons for that, e.g. TS apps could also be correlated with having more mature bug reporting systems, hence more bugs are reported, hence more bugs fixed. Another hypothesis could be that devs working on TS projects are more likely to classify something as a bug vs an enhancement. Or that they're less likely to combine multiple bugfixes into a single commit. Or that the overall speed of iteration is faster on TS projects, hence more bugs are introduced, because feature commits tend to cover more functionality at one time.

Not saying any one of those is necessarily true, just that a correlation on its own proves nothing without further investigation.

Thread Thread
 
idleman profile image
idleman • Edited

Sure, but its research. There is always a bunch a reason why something are the way they are. That is why more investigation is needed. However,if you keep in mind:

  1. JavaScript is a more simple language than TypeScript
  2. TypeScript is more code in general, more information to process.
  3. The developer experience is similar between the projects.

Makes your explanation very unlikely. Sure, it can be that way, but it's unlikely. Why should developers behave complete different in their commit-style if they have the same skill? They probably´t don't.

In science is it always extremely important to take the most logical explanation first until evidence says otherwise even if you don't like it. As newton would argue: An apple falls down to the ground. The ground does not rise to the apple.

Thread Thread
 
lionelrowe profile image
lionel-rowe

No, science is not about what seems "logical" to you, it's about empirically testing hypotheses and then observing the results in a way that's repeatable and controls for confounding variables. Gravity isn't true because Newton thought about it really hard in his armchair and logicked it out, it's true because every time you drop something it falls towards the earth unless some other force is acting on it.

Also it's kinda funny you chose that particular example, as Newtonian physics has already been superseded by relativity, and from a relativistic point of view, it's no more correct to say the apple falls from the tree than it is to say the ground rises to meet the apple.

Thread Thread
 
idleman profile image
idleman • Edited

Why do then the author himself draw that conclusion? Answer: It is the most logical. All studies is from observations and the observation says TypeScript projects has more issues and it takes longer to fix them. These are the numbers. The most simple answer is then the numbers are true, TypeScript do produce more bugs.

You think it is the only study, but its not. Multiple studies have been made about functional vs OOP, typed vs untyped and so on for decades. However, it is the best study on TypeScript vs JavaScript I know off that compare most projects and have no connection to Microsoft in any. You are free to suggest another study than goes further if you want and I will remove that part.

About the apple and the ground rises, you know. It was kinda my point. People see a apple fall from the tree instead of the ground rises because it is most logical except for those who have a belief this cannot be the case. You are similar. You want to see any explanation than the most obvious: TypeScript create more bugs. Probably because you love TypeScript.

A side note: Do you know people are prepared to do extreme things when something challenge their personal belief? Their brain do not respond the same way when personal belief are challenged. Even if you have observation that prove otherwise, do they still not believe it. You can monitor their brain and actually see it. People have committed horrible crimes in all history just because the alternative was to change their "belief". Don´t go down that road, be better.

Collapse
 
zirkelc profile image
Info Comment hidden by post author - thread only accessible via permalink
Chris Cook

@brense thank you very much for taking the time to debunk this post! 🙏

I fully agree with your points!

Collapse
 
idleman profile image
idleman

Debunked? He failed to give any objective fact and and research paper.

Thank you very much for taking the time to debunk @brense!

Thread Thread
 
zirkelc profile image
Chris Cook

I see there is no sense in arguing with since the first thing you do is to hide my comment.

Thread Thread
 
idleman profile image
idleman

Well, your comment did not include any useful information for anyone. If it did, I wouldn't hide it. This is not a "give each other back thumbs" post. Read the disclaimer.

Collapse
 
efpage profile image
Eckehard

We should also mention, that module encapsulation in Javascript is also not very strict (see here). As TS is transpiled to JS, this will affect the result anyway.

Some comments have been hidden by the post's author - find out more