TypeScript – Do we need it?

Last week Microsoft announced TypeScript, a new open source programming language.  The stated goal of TypeScript is to make it easier to write “application scale” JavaScript.

Like CoffeeScript and a few similar languages that have sprung up over the past few years, TypeScript is a language that compiles down to JavaScript, allowing the code to be run in any browser, in node.js, or in any other runtime that supports JavaScript.  Microsoft’s motivation for producing such a language is obvious: the interface of Windows 8 runs apps written in JavaScript, so putting tools in the hands of developers to make writing JavaScript easier is prudent.

Unlike CoffeeScript or other to-JavaScript compilers like SharpKit, TypeScript is built as a superset of JavaScript, so any JavaScript code is also valid TypeScript code.  TypeScript makes several optional features available on top of JavaScript’s syntax, including:

  • Static Types, allowing you to “state your intent” and have the compiler help identify where you might have made a mistake
  • Classes and Interfaces, providing a much friendlier syntax for defining data structures that JavaScript’s own
  • Modules, allowing definition and importing much like in other languages

Some of these features are already proposals for the next version of ECMAScript, the standard that JavaScript is based on, and Microsoft has taken the smart move to try and match the current proposals in its implementation of these features.  This means that you’re getting access to features that are likely to be in the future versions of JavaScript.

One of Microsoft’s real selling points of TypeScript is that having things like Interface definitions and static typing allows for lots of code completion and error detection by editors and IDEs, which in turn allows you to identify and correct mistakes quickly.  No surprises that this fits in very well with the experience of writing languages like VB.NET and C# in Microsoft’s own Visual Studio IDE.  However, other developers haven’t been completely left out in the cold – Syntax highlighting support for cross-platform editors Sublime Text,Emacs and Vim are also available.

In a world of CoffeeScript, Dart and 101 JavaScript frameworks, is there a place for TypeScript? I think there is. Microsoft haven’t overstated their goal – TypeScript is only there to add optional features to JavaScript to help developers write complex applications.  With the plethora of tools for writing cross-platform games and apps with JavaScript, as well as platforms such as Windows 8 and Open WebOS bringing web technologies to the desktop, demand for the features offered by TypeScript is only going to increase.

The TypeScript compiler is released under the Apache Licence Version 2.0, and the source can be downloaded from CodePlex.  The language specification is published on the project’s website, along with instructions for getting started.