The Pros, Cons & TypeScript
Tags: javascript, typescript, introduction
Published: 2018-11-24 20:01:09

---
title: The Pros, Cons & TypeScript
published: true
description: TypeScript not-so impartial introduction.
canonical_url: https://areknawo.com/the-pros-cons-and-typescript
cover_image: https://images.unsplash.com/photo-1489389944381-3471b5b30f04?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=4868cc90c3c515fb1316574d9aff1640&auto=format&fit=crop&w=1350&q=80
tags: javascript, typescript, introduction
---
JavaScript development has recently made a huge step forward in performance, features, syntax and development comfort in general. But still, it leaves a lot to be desired. One of the most important aspects of how good is the programming experience is mainly the editor support (at least for me). Autocompletion or Intellisense (if you are on to these Microsofty-kind-of things) is what I want to focus on. Face it, it's easier to write something when countless suggestions just bump up from under your cursor.

![via Giphy.com](https://media.giphy.com/media/o0vwzuFwCGAFO/giphy.gif)

But, as you might expect, and want them to, these cannot be just random things. These are based on types - a term not so popular in JS community. If you don't know what these are then google it and see you later. So, as you may already know types are awesome! (You may agree or not but I don't care.) They provide editor support and performance optimizations for typed languages if used correctly. But, (at least as far as I know), JS is not a typed language and it's kind of one of its main selling points. Of course, untyped languages have their own totally different pros but it's definitely not the editor support. For the time being it's not so easy to implement good autocompletion support without types. And because JS isn't becoming a typed language in the near future, some alternatives have appeared. One of which is TypeScript, a language or as I can call it "a thin typed layer" built on top of JS. This creation, with a name created by a nice game of words, is aiming to provide typed-like language experience without changing the base JS syntax. In addition, it adds support for some syntax sugar available in ES-next.

## **So... - "Long live TypeScript!" - right?**
Well... not exactly. You see, TS looks just great from the top - no new syntax (if not counting the types, of course), editor support (VS-Code especially) and "backward" compatibility with JS.

![via Giphy.com](https://media.giphy.com/media/10bdAP4IOmoN7G/giphy.gif)

You know what it means, right?

> **Backward compatibility** is a property of a system, product, or technology that allows for **interoperability** with an older legacy system, or with input designed for such a system, especially in telecommunications and computing.

*Wikipedia*

In this situation, JS isn't old or legacy - it's not important. The word interoperability is the key. In TypeScript, you can import the JS library, but it won't obviously magically generate typing for this particular code. That may not seem so, but becomes quite problematic when you want to use TS **"full-potential"** in its strict mode. Then you get some nifty errors (unless you hack your way through TS configuration) and no type-safety, which is pretty bad for my lacking. But don't worry **d.ts** (TypeScript Declaration) files are here to help! Of course only if you've got time to do a thing such as writing TS binding for some enormous library. Well, you're not alone here as well. Say hello to [**DefinitelyTyped**](https://definitelytyped.org) where other people sharing the need with you have already covered many popular JS libraries. Sadly, not all (so unexpected) and that's the main problem. You can type something that is untyped from the beginning without doing anything. But apart from this and the fact that TS type system lack some (not really needed but helpful) features, then yes - **"Long live TypeScript!"** and actually, this statement is [**becoming reality**](https://octoverse.github.com/projects#languages).

## **Other options**

At the time of writing this post, there are only two main competitors to TypeScript - [**Flow**](https://flow.org) & [**JSDoc**](http://usejsdoc.org) itself. As this wasn't meant to be about them, I'll make it clear:

### **Flow**
* OSS made by nice guys from facebook;
* It's a **type checker** not a new language;
* Has similar typing system to TS;
* Supported in most of modern editors;
* Performance is a bit laggy, but fine;
* Has smaller type base than TS;
* Better support for **React** than TS;

### **JSDoc**
* OSS project & kind of documentation standard;
* Implemented in form of **comments** in JS;
* No performance decreasement from normal JS;
* Different typing system that that of TS / Flow;
* Can be harder to create complex types than in TS / Flow;
* Supported in almost all editors;
* Documentation generator extra;

## **Personal preference**
Personally, since I discover TypeScript I can't stop using it. The editor autocompletion support it provides is just mandatory for me. I tried to use Flow and JSDoc but honestly these weren't any better than TS (just my opinion). Of course, lack of typings for some libraries can be problematic but it isn't really something I can blame TS for. So my recommendation? Just pick one of the mentioned projects, whether it'll be TypeScript, Flow or just JSDoc if you haven't already and if you have, then don't forget to share this post to those who haven't. Have a nice, typey day.