7 bad excuses for not using TypeScript
Tags: frontenddev, javascript, webdev, typescript
Published: 2019-07-08 17:38:25

---
title: 7 bad excuses for not using TypeScript
published: true
tags: front-end-developmen,javascript,web-development,typescript
canonical_url: https://blog.logrocket.com/7-bad-excuses-for-not-using-typescript-dbf5e603a9a8
---

![](https://cdn-images-1.medium.com/max/1024/1*D8Wwwce8wS3auLAiM3BQKA.jpeg)

Typescript has come a long way since its inception over [six years ago](https://en.wikipedia.org/wiki/TypeScript) and is being adopted by leading web companies. While there _may_ be good reasons to avoid using it, chances are your excuses for not using TypeScript are just bad.

In this article, I’ll cover common concerns like the learning curve, tooling, development speed, sustainability and standards compliance.

[![](https://cdn-images-1.medium.com/max/1024/1*GPjaPKNNUYHU8EsA3Z0JGA.png)](https://logrocket.com/signup/)

### 1. The learning curve is too steep

It’s important to note that TypeScript is not an entirely new language. Languages like CoffeeScript and Reason dress up JavaScript into the syntax and semantics of other programming languages — Ruby and OCaml accordingly. TypeScript pursues much more conservative goals.

Instead, it takes plain JavaScript and just adds a type system on top of it (TypeScript is a superset of JavaScript). This makes the learning curve extremely lean. Switching to TypeScript from JavaScript is not the same as switching between different languages.

Here’s a code snippet in TypeScript:
```jsx
class Greeter {
    greeting: string;

    constructor(message: string) {
        this.greeting = message;
    }

    greet() {
        return "Hello, " + this.greeting;
    }
}
```
Here’s the same code in modern (ES6) JavaScript:
```jsx
class Greeter {
    constructor(message) {
        this.greeting = message;
    }

    greet() {
        return "Hello, " + this.greeting;
    }
}
```
As Anders Hejlsberg, a co-creator of the language, puts it, [“ **if you know JavaScript, you already know TypeScript** ”](https://www.hanselminutes.com/340/what-is-typescript-and-why-with-anders-hejlsberg). Later in the article, I’ll talk more about the path of converting an existing project to TypeScript.

### 2. But JavaScript is standard, TypeScript is not

When TypeScript came out in 2012, it brought features like classes and modules, which didn’t become “standard JavaScript” until 2015, when ECMAScript 6th Edition (ES6, or ES2015) was finalized. The original implementation of modules in TypeScript deviated from ES6, but it was updated (maintaining backwards compatibility) to match the ES6 spec in the same year the standard was finalized.

Today, TypeScript language closely follows the ECMAScript spec, implementing most proposals that reach [Stage 3](https://tc39.github.io/process-document/). This means that **when you write TypeScript, you’re writing modern, standards-compliant JavaScript**. And thanks to the built-in ES3/ES5 transpiler, the output .js files will run without issues in older browsers.

### 3. It kills the dynamic nature of JavaScript

If you’ve been working with scripting languages for a while, you’ve come to appreciate the speed of development that they enable. You can freely wrangle data structures on the fly without ever having to declare them up front. This freedom, however, comes at a cost. Dynamically typed programs are much harder to reason about than the statically typed ones since there is no compile-time validation of the data flowing through the program.

Consider this simple example in plain JavaScript:
```jsx
function greeter(person) {
    return "Hello, " + person.firstName + " " + person.lastName;
}
```
By looking at the code, we can _infer_ that the person parameter _should_ be an Object with properties firstName and lastName. But there’s no guarantee that this will always be the case at runtime.

The larger your project is, the higher the chance type-related bugs will occur.

One way to shield your code against such bugs is through runtime type checks and additional unit tests like this:
```jsx
function greeter(person) {
    if (!person || !person.firstName || !person.lastName) {
        throw new Error('invalid arguments');
    }

    return "Hello, " + person.firstName + " " + person.lastName;
}

// Jasmine spec:
describe("greeter", function() {
    it("returns greeting on valid input", function() {
        expect(
            greeter({firstName: 'James', lastName: 'Hetfield'})
        ).toEqual('Hello, James Hetfield');
    });

    it("throws on invalid input", function() {
        expect(() => greeter()).toThrowError('invalid arguments');
        expect(() => greeter(5)).toThrowError('invalid arguments');
        expect(() => greeter({firstName: 'Jason'})).toThrowError('invalid arguments');
    });
});
```
But this solution is very verbose and leaves the responsibility to validate data on the developer. What if instead, we could simply add a type annotation to our function?
```jsx
interface Person {
    firstName: string;
    lastName: string;
}

function greeter(person: Person): string {
    return "Hello, " + person.firstName + " " + person.lastName;
}

// Jasmine spec:
describe("greeter", function() {
    it("returns greeting", function() {
        expect(
            greeter({firstName: 'James', lastName: 'Hetfield'})
        ).toEqual('Hello, James Hetfield');
    });
});
```
The above example is much more idiomatic and lets us focus on just validating the business logic in our tests.

TypeScript embraces the dynamic nature of JavaScript by employing a **structural typing system** and being surprisingly good at **type inference** , which means that you don’t have to be nearly as explicit with types as you would in C# or Java. Here’s an example of using the function we wrote above in TypeScript:
```jsx
let user = { firstName: "James", lastName: "Hetfield" };
console.log(greeter(user));
```
This code successfully compiles. Notice how we didn’t have to explicitly say that the user variable implements the Person interface, nor did we have to define a class that extends it. One of the language’s [design goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals) is not to create a “sound or _provably correct_ type system”, but to “balance between correctness and productivity”.

What’s also important is that the TypeScript compiler doesn’t force you to declare types everywhere, you choose how aggressive you want to be with type safety. You may even decide to apply a different level of type strictness in different areas of your project. Such flexibility is not something that traditional statically typed languages offer.

### 4. It’s not going to be around in 5 years

I’ve got news for you. Nobody has any idea what languages, tools or frameworks are going to be around in 5 years, especially in the web space. Here’s what a [StackOverflow blog author wrote](https://stackoverflow.blog/2018/01/11/brutal-lifecycle-javascript-frameworks/) about the lifecycle of JavaScript frameworks:

> There appear to be two major phases in JavaScript framework usage. There appears to be a quick ascent, as the framework gains popularity and then a slightly less quick but steady decline as developers adopt newer technologies. These life cycles only last **a couple of years**.

You work in a fast-moving industry, and if you and your project can seriously benefit from certain technology today, consider adopting it. Even if you swap it with something else in 1–2 years, the benefits you reap during that time would have accelerated your project enough to make it worth it.

### 5. It’s not community-driven

Typescript was released in 2012 by Microsoft, a proprietary software giant. Considering the reputation of the company and its development platforms, it was easy to perceive that TypeScript was meant to be “a flavor JavaScript for .NET developers”. Perhaps such perception was further reinforced by the fact that Visual Studio was the only IDE at the time with rich support for the language. Or by the fact that the project’s source code was initially published on [CodePlex](https://archive.codeplex.com/?p=typescript), a Microsoft-run GitHub alternative.

A lot has changed since then. The team behind TypeScript realized that if they wanted to see a broader adoption of the language, they needed to be better embedded in the web development community by providing high-quality tooling and listening to the feedback. They went far beyond merely putting the source code out there while continuing development in a vacuum, but fully embraced the concept of [Open Development](https://github.com/Microsoft/TypeScript/wiki/Contributing-to-TypeScript).

In 2014, TypeScript’s code was [moved to GitHub](https://blogs.msdn.microsoft.com/typescript/2014/07/21/new-compiler-and-moving-to-github/), and the development actually happens there (as opposed to developing elsewhere and just exporting new versions of code to GitHub, as seen in some projects). The project [invites contributions](https://github.com/Microsoft/TypeScript/wiki/Contributing-to-TypeScript) in the form of logging bugs, documenting proposals and submitting pull requests. The issue tracker gets regularly looked at and every submission usually gets triaged within a few days. The core team has published the language’s [design goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals) that I referred to earlier, which help the project stay true to its mission while still taking input from the community. They keep an up to date [roadmap](https://github.com/Microsoft/TypeScript/wiki/Roadmap) (a new release now happens roughly every two months), as well as document any [breaking changes](https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes).

![](https://cdn-images-1.medium.com/max/1006/0*gxKfxr1C8_pB60Gt)<figcaption>An overview of the activity on the <a href="https://github.com/Microsoft/TypeScript">TypeScript</a> project on Github</figcaption>

At the time of writing, all major cross-platform IDEs and text editors like Eclipse, Webstorm, Emacs, Vim, Sublime, Atom, VS Code, have mature support for TypeScript either out of the box or via a plugin. The core team has also put a lot of effort into creating type definition files for interoperability with existing libraries and frameworks written in plain JavaScript (more on that later). Another thing worth noting is a well-documented TypeScript Compiler API that enabled the creation of many valuable third-party language tools. Developers who use Typescript are encouraged to ask technical questions on [StackOverflow](https://stackoverflow.com/questions/tagged/typescript).

Taking all of that into account and reiterating the fact that TypeScript heavily relies on ECMAScript, I think it’s fair to say that the project _is_ _community-driven_ and has been for the past few years. Here’s what Tom Dale, a co-creator of EmberJS, [said about TypeScript](https://tomdale.net/2017/04/whats-the-deal-with-typescript/) in 2017:

> Most of all, I continue to be impressed by the professionalism of the TypeScript team. In an ecosystem that can feel built on a house of unmaintained cards, TypeScript’s drumbeat of constant, iterative improvement is refreshing.

### 6. Converting an existing project is too much work

OK, in order to take full advantage of TypeScript in your project, you _will_ have to spend time declaring types and fixing compiler errors, and that _will be_ somewhat tedious. However, authors built it with the JavaScript ecosystem in mind and provided a smooth on-ramp for adopting TypeScript on an existing project.

Per the [official migration guide](https://www.typescriptlang.org/docs/handbook/migrating-from-javascript.html), you can reap some early benefits by simply running your _existing JavaScript_ _code_ through the TypeScript compiler. At this point, the compiler will catch some low-level bugs like missing return statements at the end of functions or blocks of unreachable code. Then, you can start renaming .js files to .ts one by one and addressing new compiler feedback. The default compiler options are pretty lax, but you can turn on stricter checks. You can even use a different set of compiler options on different parts of your project, letting your teams adopt TypeScript at their own pace, using as much or as little of it as they want. The bottom line is **there is a smooth transition path that doesn’t halt development across the company,** it’s not an all-or-nothing commitment.

You can choose to convert an existing project to TypeScript gradually, or [perform a “big bang” conversion](https://www.lucidchart.com/techblog/2017/11/16/converting-600k-lines-to-typescript-in-72-hours/), or simply use it on a new project. There are also community projects like [TypeWiz](https://medium.com/@urish/manual-typing-is-no-fun-introducing-typewiz-58e3e8813f4c) that automatically add missing type information to code.

### 7. But all of the libraries I use are in JavaScript

To enable interoperability with existing JavaScript code, the language supports TypeScript Declaration Files. For example, if a JavaScript library you use exports a global function called camelize, a TypeScript declaration for it would look something like this:
```jsx
declare function camelize(s: string): string;
```
After you import such declaration into your project, the TypeScript will know about the function’s types.

In the same year, TypeScript was released, [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped), a community repository of declaration files for popular libraries, was created. At the time of writing, it contains declarations for over 5,000 JavaScript packages. Using these declarations is extremely easy. For example, if you use Jasmine testing framework in your project, simply run:
```jsx
npm install --save-dev @types/jasmine
```
The types will then be automatically included by the compiler, and you’ll get on-the-fly type checking and autocomplete in your code editor. All or most of the packages you use should already have high-quality type declarations created for them, either bundled in or available via the DefinitelyTyped repo. The engineering team at Slack shared [their experience](https://slack.engineering/typescript-at-slack-a81307fa288d):

> Looking ahead and thinking about code maintenance, we appreciate the ecosystem around TypeScript. As heavy users of React and the Node/npm ecosystem, the availability of type definitions for third-party libraries is a huge plus. Many of the libraries we import are already TypeScript compatible. If definitions do not ship with the module itself, they are likely to be found in the fantastic [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped) project. React, for instance, does not ship with type definitions, yet a simple npm install @types/react installs them with no further configuration required.

### Conclusion

Using static type checking helps you eliminate a whole class of bugs, and TypeScript is the most popular static typing solution for a Node/JavaScript project. It may not be worth it on a relatively small or experimental project, but the benefits far outweigh the added overhead on a large-scale project, [as proven](https://www.typescriptlang.org/community/friends.html) by companies like Google, Slack, Asana, Ember and others. Hopefully, this article has given you a fresh perspective on TypeScript and addressed some specific arguments against it that are no longer relevant. Maybe it’s time for you to give it another chance.

Are you currently using TypeScript or planning on using it? If not, what’s holding you back?

P.S. It’s worth noting that there is another project that adds static types to JavaScript while preserving the language syntax and semantics, it’s called [Flow](https://flow.org/). Be sure to check it out if you’re looking for alternatives to TypeScript.
* * *
### Plug: [LogRocket](https://logrocket.com/signup/), a DVR for web apps

[![](https://cdn-images-1.medium.com/max/1024/1*s_rMyo6NbrAsP-XtvBaXFg.png)](https://logrocket.com/signup/)<figcaption><a href="https://logrocket.com/signup/">https://logrocket.com/signup/</a></figcaption>

[LogRocket](https://logrocket.com/signup/) is a frontend logging tool that lets you replay problems as if they happened in your own browser. Instead of guessing why errors happen, or asking users for screenshots and log dumps, LogRocket lets you replay the session to quickly understand what went wrong. It works perfectly with any app, regardless of framework, and has plugins to log additional context from Redux, Vuex, and @ngrx/store.

In addition to logging Redux actions and state, LogRocket records console logs, JavaScript errors, stacktraces, network requests/responses with headers + bodies, browser metadata, and custom logs. It also instruments the DOM to record the HTML and CSS on the page, recreating pixel-perfect videos of even the most complex single page apps.

[Try it for free.](https://logrocket.com/signup/)
* * *
The post [7 bad excuses for not using TypeScript](https://blog.logrocket.com/7-bad-excuses-for-not-using-typescript-dbf5e603a9a8/) appeared first on [LogRocket Blog](https://blog.logrocket.com).