This is why I hate Typescript
Tags: typescript, javascript, node
Published: 2019-07-19 18:57:16

---
title: This is why I hate Typescript
published: true
description: And why you should stop using it immediately 
tags: typescript, javascript, node
cover_image: https://thepracticaldev.s3.amazonaws.com/i/rkyvil6x89ger1yhwr7j.jpg
---

> 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:
```ts
class Foo {
  bar = 0;
  baz = 0;
}
```

A class in Javascript:
```js
function Foo() {
  this.bar = 0;
  this.baz = 0;
}
```

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

```js
class Foo {
  constructor() {
    this.bar = 0;
    this.baz = 0;
  }
}
```

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! [<sup>(Yet)</sup>](https://github.com/tc39/proposal-class-fields).

### Private properties

Well, JS does not have private members, but when it does, it will be something like:
```js
class Foo {
  constructor() {
    this.#bar = 0;
  }
}
```

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

```ts
class Foo {
  private bar = 0;
}
```

Ugly! And they are not even working on it! [Aren't they](https://github.com/microsoft/TypeScript/wiki/Roadmap#future)? 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:
```js
function factorial (n) { 
  if (n == 0) return 1;

  return n * factorial (n-1); 
}
```

In TS:
```ts
function factorial (n) { 
  if (n == 0) return 1;

  return n * factorial (n-1); 
}
```

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


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

  return n * factorial (n-1); 
}
```

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](https://en.wikipedia.org/wiki/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](https://en.wikipedia.org/wiki/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](https://en.wikipedia.org/wiki/Turbo_Pascal), and [Delphi](https://en.wikipedia.org/wiki/Delphi_(IDE)). 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](https://www.typescriptlang.org/play/index.html#code/MYGwhgzhAEBiD29oG8BQBIARmATtAvNAMwDcG2AXgcWQL5A) vs [Babel](https://babeljs.io/repl/#?babili=false&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=MYGwhgzhAEBiD29oG8BQ1oCMwCdoF5oAGAbnSzAC8DiyBfVIA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=es2015%2Creact%2Cstage-2&prettier=false&targets=&version=7.5.5&externalPlugins=)

## 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](https://facebook.github.io/create-react-app/docs/adding-typescript) [have](https://medium.com/the-vue-point/plans-for-the-next-iteration-of-vue-js-777ffea6fabf#1855) [never](https://nextjs.org/learn/excel/typescript) [seen](https://github.com/nestjs/nest) [another](https://github.com/ant-design/ant-design) [project](https://github.com/apollographql?utf8=%E2%9C%93&q=&type=&language=typescript) [using](https://github.com/typeorm/typeorm) [Typescript](https://www.typescriptlang.org/). [No one](https://2018.stateofjs.com/javascript-flavors/overview/) 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](https://github.com/facebook/jest/pull/7554) 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.