DEV Community

Discussion on: To Typescript Or Not To?

Collapse
 
latobibor profile image
András Tóth

I will write about "Toxic flexibility" soon. The fact that I can do this in JS:

var foo = {
 doMagic() {
   console.log(this.somethingNotYetDefined + ['55'])
 }
}

bar.somethingNotYetDefined = 123;
bar.doMagic();
Enter fullscreen mode Exit fullscreen mode

can be great when your project is 1 file under 200 lines, but not when you have multiple developers working on hundreds of files. This level of flexibility means that you cannot trust any line of code, you have to read every line of every function you call and even then there might be somewhere some code that for fits and giggles change the very object you trust.

Not to mention the living documentation part of having types of parameters and return types. A smart engineer will know how to communicate with those. I have also found that it makes you write simpler code: having functions where clear inputs create clear outputs. Things that are impossible to type tend to be the ones having the most esoteric bugs and edge cases.

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

the language lets you do that, but if you do that... well.

I also can make a calculator App and do something like:

function sum(num1, num2) {
    return num1.toString() + num2;
}

if you do stupid things that are or can become unpredictable, don't blame the language

Thread Thread
 
latobibor profile image
András Tóth

I get your point, but there's one entirely other aspect than fellow engineers: IDEs. IDEs do not know if you are a bad engineer or a good one. Therefore they have to treat every line of code as I wrote above: with the chance of it horribly mutating.

The whole reason about Typescript if you read the interviews was give better tooling. When you opt-out of it you opt-out of better tooling.

The irony is that even for hardcore, ultra conservative JS developers the advantages of TS is seeping in: if the package you use have typings your IDE would be able to use that info for code completion.

Thread Thread
 
joelbonetr profile image
JoelBonetR 🥇

Another good contribution to the discussion, this is converting into a gold mine, thanks András

Thread Thread
 
latobibor profile image
András Tóth

dev.to/latobibor/toxic-flexibility...
As I promised, here is the article.