DEV Community

Cover image for This is why I hate Typescript
Michael De Abreu
Michael De Abreu

Posted on • Edited on

This is why I hate Typescript

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.

Latest comments (107)

Collapse
 
desone profile image
Desone
Collapse
 
desone profile image
Desone

Read this article and you will know why typescript is taking over:

medium.com/me/stats/post/85c30a370ef5

Collapse
 
atonchev profile image
a-tonchev

TypeScript is a joke, that makes programmers stumble

Collapse
 
kruzus profile image
Bek

I love reading articles written by beta developers.

Collapse
 
cdecompilador profile image
cdecompilador

I understand the point, I came to Typescript from languages like c, c++ and rust just because of the strongly typed system, but I encountered many bad thing on it, generics are horribly bad implemented (the compiler does not infer the generic if there are too many indirections), the language lacks many functional features that reinforces your point, made by OO programmers to OO programmers, it would be great to have algebraic data types, unions, a better generic system (or use templates/traits). But still the idea is great in my opinion, an option that is done better in my opinion is haxe (compiling to javascript) but still not very popular.

Collapse
 
michaeljota profile image
Michael De Abreu

This are actually the best valid points to "hate" TS. The inferences could work better, and I know they are working hard to make them work better without having to sacrifice performance. I understand that the main goal of TS is to balance between correctness and performance, but it still need some work in that. Recent versions of TS shown better understanding and better syntax to use generic, and there is even a couple of proposals to declare named generics, and to infer other generics members.

Collapse
 
djmisterjon profile image
DjMisterJon

TS should using only by IDE to provide good type for vanilla dev.
TS is good if you build API logic.
But is hell for use in project.
Use js+jsdoc if your IDE support.
in most case you get all reference in your project.
If your IDE not understand your js file, add some jsdoc +ts logic.
And if is not work , well , create a .ts file !
But ts is the last choice.

Learn jsdoc plz, this is the good way to doc and make ref to your logic.
/**
* App
* @param {object} props Component props
* @param {React.ReactNode} [props.children] Childrens passed by parents
* @param {function(MouseEvent|React.PointerEvent):void} [props.onChange] - Using function():return
* @param {import('csstype').Property.FlexDirection} [props.FlexDirection] - Using Import()
* @param {React.CSSProperties['flexDirection']} [props.FlexDirection] - Using array ['propkey']
* @param {Container.prototype['props']['orientation']} [props.orientation] - Using componment propTypes
*/

Microsoft with vscode (IDE) work hard to give good jsdoc support mixed with TS logic.
typescriptlang.org/docs/handbook/j...

Collapse
 
ortonomy profile image
🅖🅡🅔🅖🅞🅡🅨 🅞🅡🅣🅞🅝

I feel like the satire intentionally missed that it makes code sometimes unreadable, especially if the author has to use generics , R, S, T, U to make their typings work. This is a genuine frustration of using TS.

Collapse
 
michaeljota profile image
Michael De Abreu

You know, you can name your generics as you want. If someone is using R, S, T whatever, and you blame TS for it, is the same as someone naming a variable a, b, num, and blame the language for it. Of course, it makes more verbose the code, but is the price to pay for a better UX while developing.

Collapse
 
ufadacom profile image
Ufada Classifieds

I also like staying with Native JavaScript, don't feel I can gain anything to adapt TypeScript.

Collapse
 
motss profile image
Rong Sen Ng

Would you like to give it another try before the end of the this year? See if it has any improvements so far to address the issues you stated?

Collapse
 
alexmorleyfinch profile image
Alex

I get that you're taking the piss, and that's all this is. A laugh. Nobody would seriously use this as an example to compare TS to JS. None of these points are valid, but yeah, let's all laugh at the Typescript noobs that don't actually know what they're talking about. Ahhh, the good life...

Collapse
 
michaeljota profile image
Michael De Abreu

Hate Typescript. Sorry to disappoint you, but as I said, most of this points (if not all of them) are actually the point of view of one or more people who really think ts is bad.

Some comments may only be visible to logged-in visitors. Sign in to view all comments.