This is why I hate Typescript

Michael De Abreu - Jul 19 '19 - - Dev Community

This a satire post about some arguments that you can actually find against Typescript. Through most of them are being exaggerated, they all represent an opinion of one or several people.

Typescript is not standard

Typescript is just a big amount of garbage on top of the most wonderful language on ever created, JavaScript, and it's not even trying to follow the standard of JS. I will give you examples of how TS does not follow ES standards.

Modules

TS has its own module system, called namespace. What is a namespace you may ask? It's a thing that Microsoft invented to totally ignore ES standards modules. I doesn't matter that ES6 modules wasn't really defined when TS was first announced, Microsoft should have know! Also, I don't care if TS now support ES modules, namespaces should have never existed and they should disappear!

Classes

Much like TS have namespaces, they have their own way to declare a class.

A class in Typescript:

class Foo {
  bar = 0;
  baz = 0;
}
Enter fullscreen mode Exit fullscreen mode

A class in Javascript:

function Foo() {
  this.bar = 0;
  this.baz = 0;
}
Enter fullscreen mode Exit fullscreen mode

And you may argument that I'm writing ES5 style classes, but even with ES2015, JS looks much better!

class Foo {
  constructor() {
    this.bar = 0;
    this.baz = 0;
  }
}
Enter fullscreen mode Exit fullscreen mode

You can also say that when TS introduced classes, the JS classes proposal wasn't defined, sure. But why they are using class field declarations? They are not standard! (Yet).

Private properties

Well, JS does not have private members, but when it does, it will be something like:

class Foo {
  constructor() {
    this.#bar = 0;
  }
}
Enter fullscreen mode Exit fullscreen mode

Now, TS does support for privare members, but how does it looks in Microsoft language?

class Foo {
  private bar = 0;
}
Enter fullscreen mode Exit fullscreen mode

Ugly! And they are not even working on it! Aren't they? Like this wasn't enough, "private" members in TS are not really private, as you can access them with bracket syntax!

Typescript is not JavaScript

Take any current ES code and try to compile it with a fresh new TS project. You won't be able to do it. Because Typescript is not JavaScript! Not even a simple factorial function.

In JS:

function factorial (n) { 
  if (n == 0) return 1;

  return n * factorial (n-1); 
}
Enter fullscreen mode Exit fullscreen mode

In TS:

function factorial (n) { 
  if (n == 0) return 1;

  return n * factorial (n-1); 
}
Enter fullscreen mode Exit fullscreen mode

You now have two errors because TS can't understand what you are doing. You have to write in a syntax Typescript understand.

function factorial (n: number): number { 
  if (n == 0) return 1;

  return n * factorial (n-1); 
}
Enter fullscreen mode Exit fullscreen mode

There you have it TS! Now you, and most likely any other person in the world reading only the signature, will know what the function is supposed to return, and what the argument type supposed to be. I don't want to write that. Why TS can't understand that I'm returning the same function that will eventually return a number? Besides, if I want someone else to understand my code, I'll comment it, or add unit testing. That's what you need for anyone to understand the code. Beside, that's an elemental function, what needs to be explained any way? You can't be so ignorant to not know what a funcional recursive pure function does!

And you may say that I have to change the compiler options, and disable implicit any for this error to go away. But I would like better for TS to understand my code.

The creator of Typescript knows nothing about programming

I will start that Microsoft is the father of all evils, and Typescript was created by Microsoft. It does not follow any standard as I explained above, and only was created to extinguish the web development as we know it. Always remember the Microsoft moto: Embrace, extend, and extinguish. That happened almost 20 years ago, but make no mistakes, corporations does not change! Microsoft is the same old company that wants to control everything!

Second, if you look up who is one of the main developers of Typescript, and most likely the one that had been shaped it for years, you will find Anders Hejlsberg. What does he knows about programming? Is an old man that knows nothing about standards. He just had developed programs like Turbo Pascal, and Delphi. And the only thing about languages that he knows, he had done it because is the lead architect of C#. I'm sure anyone in the community would do better.

People only use Typescript because they are used to OO languages

Developers that prefer use Typescript instead of JavaScript, are just frustrated that JavaScript is a functional programming and would rather ignore all the good features of JavaScript and write in the good old object oriented way, and becoming front-end developers wanna be in the way. You have to break the chains bro! You need to understand the freedom that JS give to you and embrace it! And you only can accomplish this if you use JavaScript the old fashion way.

Ok. I will be serious in this section, as this is mostly true. Most of the developers I know that are coming from a OO language, as C# or Java, will try to use TS the way they are used to use those languages. And that is a real problem. TS is not magical sugar on top of JS. You really need to understand JS in order to understand what is TS actually doing for you. If you don't, you will probably end up writing more code than you should, using anti-patterns, and creating more bugs that intended

You can't debug Typescript

Do you use Webpack, Parcel or any build tool that produce source map? Why? You have to stop and just write plain old JavaScript. Because if you compile down you probably will need something else to debug your code. It's better if you write code you can debug only by using the developer tools of IE.

Babel is so much better

I already said that Typescript is not Javascript. But Babel is. Is standard JS that compiles down to standard Javascript. Just compare it: Typescript vs Babel

Typescript is only used in Angular

That's why I don't like Angular either. I've never seen another project using TS. Let me repeat that for you I have never seen another project using Typescript. No one likes Typescript.

Flow is better

Because, why you want another file extension that explicit states you are not writing JS when you can just write types in .js files? Besides, it's support is getting better, with more projects being writing with Flow.

You shouldn't use Typescript

If... You are not confortable. In case you didn't notice it, this is a satiric post, about the people who complains about TS. I'm not saying you should use TS everywhere, I'm sure if you want to do a To-Do app, it would be safe doing with JS. But in my experience, if you are working with more than 3 people TS will help more than it hurts. And I have to say, when you don't know JS, using TS hurts a lot. But I don't think that's on the Typescript team, that's on us.

As developers, we need to learn every language is a tool, that will help us with something. Sometimes you need a hammer, sometimes you need a star key. Not every language fits to everything, and maybe you don't like to use a hammer when you are used to use a star key. But can't just shoot that every one that's using a hammer is wrong, or that they should instead use a star key.

You may as well learn how to use the hammer.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player