TypeScript and the Future of JavaScript

TypeScript and the Future of JavaScript

I’m not bashful about my enthusiasm for JavaScript (can enthusiasm be bashful?).  But as many others have pointed out, JavaScript kinda sucks.  And even though ES6 (the next version of JavaScript) has features to help resolve a lot of the pain, developers can’t really use ES6 on public websites for another three to six years.  Remember, up until very recently, web developers were expected to make websites compatible with Internet Explorer 6 (Hello 2001!).

ES6 is the future, and it’s here right now, but we can’t use it yet.  So what can we do as JavaScript developers to make our lives better?

There are two answers emerging.  One is to write in ES6 and run it through a compiler that “transforms” it into ES5, the current version of JavaScript.  The other is to write in different language entirely, such as Dart or CoffeeScript (get the pun?), which can be compiled into ES5.  Either way, you can write run-anywhere code, but work in a language with fewer pitfalls.

But not so fast!  Remember, learning a language takes time, and mastering it takes even more time.  And writing in a language that writes a language ( Dart-> JavaScript)?  That means you need to know both languages, despite any claims to the contrary.

I have a pet peeve with code that writes code.  Unless it’s a commercial product, or a popular open source tool, I avoid it because it’s just too easy to write buggy code, which in turn generates more buggy code.  I write all my bugs by hand, thank you very much.

Kidding aside, I recommend getting good at JavaScript before learning a language that writes JavaScript.  Every language has its own idiom, it’s own style, and it’s important to know and use that style.  It’s like speaking in an accent; every place has their ways of saying things, shorthands, and conventions that are accepted or expected by the community.

With that said, I’m very excited about what’s going on with TypeScript.  In part because the tools are so impressive, but also because it’s a superset of JavaScript.  That’s right: your JavaScript is valid TypeScript.  You can write in ES5, or you can add ES6 features and compile down, or you can use the full TypeScript language, which gives you static types, interfaces, modularity, and of course it still compiles down to ES5.  In fact, it will compile to any version of JavaScript you want; just edit the config file.

The takeaway is that you write in real JavaScript, and then add as much “magic” as you want.  I am not going to write about how to use TypeScript- a lot is being said about that, and Anders Hejlsberg does a better job than I could.  Go ahead and watch that video- it’s long, but so good.

Where This Matters

The reason I’m so optimistic about TypeScript versus Dart or CoffeeScript is that TypeScript tries to make JavaScript better, not leave it behind.  You can take or leave any part of the tool chain.  The end goal of course is to make it easier to write and maintain sophisticated JavaScript apps.  JavaScript wasn’t really designed to build large apps, so TypeScript fills in the gaps, but it’s still JavaScript.  Head over to the TypeScript Playground and see for yourself.

Have you used TypeScript, Dart, CoffeeScript, or one of the ES6 transpilers?  What are your thoughts?

Submit a Comment

Your email address will not be published. Required fields are marked *