Unsurprisingly, quite a few people see TypeScript as suspicious, at best. And that's fair enough -- at the end of the day, even TypeScript compiles down to raw JS. It's not like we absolutely need an intermediate step. Being a purist myself, I understand the sentiment!
Table of Contents
But, there are real benefits to the extras that TypeScript brings, whether you use it or not; and there's no reason for suspicion, either way.
There are a number of reasons people build transpiled languages, but at the top of the list are:
- Additional features; and
- Freedom to innovate.
Transpiled Languages Add Features
Transpiled Languages Are Free to Innovate
# Ruby-style comments w/ hash, no semicolons, only arrow functions Person = (name) => # @ indicates 'this' @name = name @speak = () => console.log @name return @ Me = Person('Peleke') Me.speak()
- Functions are defined with
->, not the function keyword
. . . And CoffeeScript doesn't allow
==, either: It forces
I'll talk about a few of these, but would like to call out a few of TypeScript's less-discussed strengths:
- Support & Toolchain Improvements; and
There's a lot of talk about TypeScript's features. There's a lot less about why they're there.
Regardless, the fact remains that people are more productive when they're comfortable with their tools
If TypeScript makes developers more productive, they can -- and should -- use it. Forcing them through a largely idiolectic learning curve just to get things done is impractical in real projects.
TypeScript also has the advantage of having some giants behind it.
Whereas most compile-to-JS languages are community efforts, TypeScript is an official Microsoft endeavor. They've put a lot of time into developing it, and users can rest assured that they'll have long-term support from the tech giant should they migrate to TypeScript.
TypeScript has support for all the most popular editors including Sublime Text, Atom, Eclipse, Emacs, WebStorm, Vim, and of course Microsoft's Visual Studio family.
It's used in a number of real-world projects, too, so you can trust it's robust enough to handle just about anything you're working on:
Black Screen is an OS X terminal emulator & IDE.
Angular 2's main codebase is written in TypeScript, and a substantial proportion of the community is sure to jump on board with it.
Microsoft's Salsa service, which powers part of Visual Studio, also uses TS.
Take a look at the list of TypeScript users.
Whether or not you use Angular 2 or Visual Studio, that kind of endorsement from both Microsoft and one of Google's most prominent web teams should help you sleep at night if you're about support and longevity.
That means you can use the features that help you think, and forget about the ones that don't. When I write TypeScript, I don't use classes, mixins, generics, or enums, but I do use type annotations, aliases, and ADTs quite a bit.
You might choose to use exactly the tools I don't, or toss in a type annotation only every once in awhile. That's fine with TypeScript: You can use as much, or as little, as you want. It is not an all-or-nothing commitment: It's only as total as you make it.
You can use as much, or as little, as you want. It is not an all-or-nothing commitment: It's only as total as you make it.
Even if TypeScript does bring a lot to the table, the question as to why we need another compile-to-JS language remains a fair one.
Different projects pose different engineering challenges, and different languages provide different sets of solutions and tradeoffs. Different compile-to-JS languages take different approaches to solving the problem of simplifying, streamlining, and strengthening the engineering process.
That means they end up solving different problems in dfferent ways, and are particularly suited to specific tasks. CoffeeScript lends itself well to configuration files and beautiful tests, neither of which I'd ever prefer to write with TypeScript.
Anders Hejlsberg identifies two fundamental differences between TypeScript and CoffeeScript:
- ** CoffeeScript does not feature static typing **. This is mostly relevant to folks who use IDEs (some of us don't).
The most obvious difference between the two approaches are that:
- TypeScript is ** largely unopinionated *k but seeks to be * better equipped to scale **, whereas
- CoffeeScript ** builds its opinions into the language **, and adds no extras explicitly intended to ease the creation of large applications.
Dart is syntactically more similar to TypeScript than CoffeeScript, but departs substantially from both languages with regard to its design philosophy.
- Dart makes different syntactical choices; and
- Is flexible with what you leave and what you take;
- Enables more powerful tooling; and
For my part, I use TypeScript whenever I work with Angular 2 or Rx.js, and when writing heavily functional code (I've got a habit of typing functions). The rest of the time, I stick to vanilla JS. Switching between the two is simple enough I don't think about it anymore.
Whether you use it or not, TypeScript has some indisputable strengths, and experimenting with it is instructive. If you're open to trying something new, give the documentation a glance, write something small, and see how you feel. If you love it, now you know. If you hate it, that's fine too -- just change the extension back to
.js and get back to it!
How do you feel about TypeScript? Love it? Hate it? No opinion? Whatever they are, leave your thoughts in the comments, or shoot them to me on Twitter (@PelekeS)!