Microsoft is getting into the compile-to-JavaScript language game by announcing TypeScript today. TypeScript is a “typed superset of JavaScript that compiles to plain JavaScript”, and Microsoft is billing it as “a language for application-scale JavaScript development”, though it’s not like we haven’t been able to build applications with normal JavaScript in the past.

TypeScript is a self hosting compiler (meaning that the compiler itself is also written in TypeScript), and it can be installed using npm. In many ways, it looks like TypeScript is Microsoft’s answer to Google Dart, however TypeScript appears much more JavaScript like than Dart does, and in fact it is given that it is a superset of JavaScript.

The types in TypeScript are annotations: an optional way of recording and enforcing types. The compiler will give you compiletime warnings when calling a function with an incorrect signature for example.

TypeScript also supports interfaces, classes (the same syntax as currently proposed by the next version of EcmaScript), modules, file importing, public and private data, and probably more. The documentation appears to be a little lacking at the moment, but you can check out a quickstart guide, some sample source code, and of course the source code of the compiler itself on Microsoft’s source code website.

You can also try out the project using their interactive environment where the code is compiled from TypeScript to JavaScript as you type. It looks like the compiled output is very readable, much like CoffeeScript aims for, and the syntax looks fairly straightforward. This doesn’t do nearly as much as CoffeeScript and Dart do though: just a few features, and mostly the same old JavaScript that you’re used to. Given that, this could catch on.

TypeScript has support from Microsoft’s development environment Visual Studio of course, and other editors will work fine as well. It works in the browser, Node.js, or any other JavaScript environment, and the type checking is performed at compile time, so as not to waste processor cycles at runtime. I’m not sure if Source Maps are supported or not, but that would be cool if they were…

Here is a video of Anders Hejlsberg, the author of the language at Microsoft introducing TypeScript.

Anyway TypeScript looks interesting, and it’s great to see Microsoft playing the JavaScript game. You should definitely check it out, and let me know what you think in the comments!