Tuesday, October 2, 2012

TypeScript - Microsoft's Replacement For JavaScript


Microsoft has just announced a new programming language - TypeScript. It's targeted at replacing JavaScript by being more maintainable in large projects. Do we need yet another JavaScript replacement?

Everyone seems to have a replacement for JavaScript - Google even has two. Now Microsoft has revealed that Anders Hejlsberg has been working on a replacement and it has released a preview of TypeScript.
TypeScriptlogo
TypeScript is open source - Apache 2.0 license -- and a superset of JavaScript. As you would expect from a Hejlsberg language it incorporates type checking, interfaces and lots of syntactic sugar. 
The good news is that it is compatible with JavaScript - you can simply load JavaScript code and run it. JavaScript programs are TypeScript programs. The TypeScript complier outputs JavaScript so compiling a JavaScript program is just a pass though operation.  To improve on JavaScript, TypeScript lets you include annotations that allow the compiler to understand what objects and functions support. The annotations are removed by the compiler, making it a zero overhead facility.
It also adds a full class construct to make it more like traditional object oriented languages. Not every JavaScript programmer will be pleased about the shift in emphasis, but the way it compiles to a JavaScript constructor is fairly transparent.

typescriptclassA