So, TypeScript

Microsoft has just unveiled TypeScript, a new JavaScript-like language that compiles to regular JavaScript. It adds a lot of syntactical features to the platform, many of them coming from the ECMAScript 6 (“Harmony”) proposals. It has the pedigree to be great – as Mark Rendle wrote:

It’s been known for some time that Anders Hejlsberg was doing something interesting in the JavaScript space, and when Anders is doing something interesting, it’s worth paying attention. This is, after all, the man who got Real Programmers to use Pascal, and pulled off C++++ (put two of the +’s over the other two: #! See what they did there?). Today the covers were taken off the latest project by the man himself in this Channel 9 video, and it’s TypeScript: “a strict superset of JavaScript that compiles to plain JavaScript”. What “strict superset” means is that all the valid JavaScript that already exists is also valid TypeScript; it’s like the relationship between C++ and C.

Despite the lack of a beard, Anders Hejlsberg is a guy you should respect – he came up with two of my favorites, Turbo Pascal and C#. But while the language looks great – as an ActionScript programmer, it’s easy to love it – I see two issues with this approach.

First, using a compiled language takes away some of the advantages of using pure JavaScript – which is testing and debugging in a browser without any kind of additional step needed. Compiled code is great if you’re talking about deploying production code, but less so if you’re still building and testing. I would have preferred a pure ECMAScript 6 compliant browser (if/when an actual standard exists) that allows you to test your code natively; one could then use compilation before deploying, to ensure backwards compatibility until browsers catch up. This could be dampened (and then some) with on-the-fly, server-side compilation, but it’s not very clear to me whether that’ll be possible.

Second, and maybe more importantly, this is Microsoft, and I can’t help but seeing them taking the language to the direction they want (even though it’s an “open standard”) rather than bringing them closer to ECMAScript 6, or following it strictly (they don’t actually mention ECMAScript anywhere in their website, so even thinking they’re gonna follow it loosely is optimistic they do mention that TypeScript is “closely aligned” with ECMAScript 6 on the language’s specification PDF). I’m not aware of their full policy on that, and maybe I’m being too harsh on them, but similar things have happened in the past.

With the introduction of TypeScript, CoffeeScript, Dart, and many many more alternatives to JavaScript, it’s easy to say that there’s a plethora of syntactical features programmers would like to see added to the language. Here’s to hope that there will be a point in the future where the main language becomes a better solution for those people, rather than each different programmer deciding on their own fringe solution for the same problem. As a developer, I’d rather see people investing their time – and open-source libraries, and tutorials, and examples – in one main platform rather than in dozens of them.

Unfortunately, so far, I don’t see that happening. But that’s the future we bought, so it’ll have to do.

Update (Oct 05): in retrospect, the more I look at TypeScript, the more I like it. The fact that it runs as a Node.js script is pretty good – it makes it a snap to be used by most automated build systems. If they add TypeScript support to WebStorm, I can definitely see myself using it a lot for my own libraries instead of my current JavaScript code.

  • Hi, thanks for the pingback. Couple of things: the language specification for TypeScript does reference ECMAScript 6 by name for the class syntax; and there is experimental support for source maps in the compiler which will enable browser-based debugging (in Chrome and Firefox; IE doesn’t support source maps yet). I presume the VS2012 tooling will eventually provide TypeScript-source debugging, too.

    Regarding the future of the language and its ongoing relationship to JavaScript, watch this video with Anders, Luke and Steve talking about the project:

    They seem to be committed to the idea that JavaScript is a good language with a great future that they want to contribute to.

  • Zeh

    Mark: thanks. Color me corrected. I’ve searched for ECMA on their specification PDF and couldn’t find it, and didn’t see it anywhere on the website, hence why I assumed they were intentionally leaving it out. I did a search in their PDF again and *did* find several instances, so I guess I screwed it up before (maybe the PDF wasn’t fully downloaded). Oops.