DEV Community

Cover image for **** TypeScript
Bryan Maynard
Bryan Maynard

Posted on

**** TypeScript

I am so sick of TypeScript.

No, that's not entirely true. TypeScript is fine.

I'm sick of people saying garbage like "No developer who uses TypeScript will ever go back to JavaScript."

I'm a JavaScript developer. I've been working in JavaScript for 15 years.

Let's dive into this.

Benefits of TypeScript

I understand why TypeScript was created. TypeScript was created to:

  1. Help large, ultra-complex projects eliminate entire classes of bugs
  2. Make the boundaries between apis and sections of codebases clearer (very helpful for large projects/teams)
  3. Give dev tools (like IntelliSense) additional information so they can be more useful

It does these things extremely well.

Something to keep in mind

The point of development is not to write perfect code. The point of development is to produce useful things, gain understanding, and grow over time.

Benefits of JavaScript

JavaScript is an elegant language. It's syntax is relatively simple and extremely flexible. This has lead to things like CoffeeScript, LiveScript, and the rise of transpiling (which has lead to an explosion of helpful tools for development - and allows us all to use the coolest new features of JavaScript before they're fully supported by browsers).

JavaScript also supports a wide variety of coding styles. For a developer, their coding style is their voice. Crucially, JavaScript gives developers many, many options to choose from when finding, crafting, or evolving their coding style.

Additionally, JavaScript is the simplest, fastest way to get a project from zero to doing something useful. Period.

Something to keep in mind

The elegance that enables all this comes at a cost. That cost is implicit knowledge. Implicit knowledge is the collection of things you know, but that you forget you know because you're so used to them. Implicit knowledge is the lifeblood of JavaScript.

An example of implicit knowledge is truly understanding how this works in JavaScript. Once you get it, you hardly ever think about it because you write code is ways that don't cause problems.

The More You Know

Most problems people face when working with JavaScript are symptoms of inexperience or lack of knowledge; people lacking the implicit knowledge to understand (or, at least, have some idea) why problematic code is behaving a certain way.

To people in this situation, TypeScript can end up looking like much more of a savior than it actually is.

TypeScript is basically just a linter with a lot of context. Linters can be useful, but they provide no value on their own. Why? Because they don't actually do anything. They just take away options.

For someone new to JavaScript, or new to programming, this can be very helpful. When there is only one way to do something, the path forward is clear.

It's crucial to understand, however, that TypeScript is JavaScript. It's not a distinct language. When your code executes, it's executing JavaScript. Just JavaScript.

Another way to think about TypeScript is JavaScript with blinders on. Blinders help a horse go straight, but cause all kinds of problems when they fall off mid-race.

At some point a problem will occur that TypeScript cannot help with. When that happens, all the intrinsic knowledge about how JavaScript works under the hood not gained via trial and error will be felt. And it will hurt.

Problems with TypeScript

TypeScript's rules can easily clutter code to the point that it's intent gets muddled. Sure, the types the code is working with are extremely clear, but what the code is actually doing gets harder to understand as that's not the only thing you're focusing on when reading it. TypeScript adds cognitive load. In some cases and for some people that additional load is worth it and the code overall benefits.

In some cases the cognitive load added by TypeScript is not worth it. A senior JavaScript developer, for example, may not benefit from TypeScript as the rules it mandates may be redundant or, worse, counterproductive; the senior developer understands JavaScript well enough that they don't need TypeScript to make things explicit or remove options.

Removing options can be helpful. It can also unnecessarily complicate or bloat code.

Additionally, for projects that are not massive and ultra-complex, or projects with small (possibly even one-person) teams, TypeScript may not provide any value at all as everyone may already be on the same page and/or want different coding styles in the codebase so team members can learn from each other.

Closing thoughts

JavaScript offers about the lowest-possible barrier to entry for people wanting to get into programming and web/app development. Artificially raising that barrier by claiming that "real developers" use TypeScript instead of JavaScript helps no one.

Each developer deserves to find, and have, their own coding style; every developer deserves their own voice.

TypeScript has it's place, so does JavaScript.

Top comments (1)

Collapse
 
blindfish3 profile image
Ben Calder

I have a feeling your click-bait title might have worked against you (why so few reactions?!); which is a shame because what you've written is actually a really well balanced critique of TS.

One point I'd add: I've sometimes seen comments from junior devs who have completely misunderstood what TS actually does: they assume that it also performs run-time type checking 😱
That false belief that their code is completely type-safe can result in code that will break badly once it's subjected to real-world data from unpredictable APIs; and it's much harder for them to fix because they're convinced type errors can't happen in their code 🙈

Thanks for the article!