JavaScript has bad parts. Creating structured application in JavaScript is not easy. Yesterday, Anders Heljsberg announced his new project, TypeScript, which tries to make application development with JavaScript easier .

TypeScript is an extension to JavaScript, similar to LESS for CSS. It will be compiled to JavaScript just like CoffeeScript. However since it is a superset, it still accepts JavaScript syntax.

TypeScript is definitely friendlier for people from statically typed language background. There are built in keywords like interface, class, access modifiers (like private), inheritance, and module (namespace) system. And since this is from Microsoft, its Visual Studio integration is a definite feature.

interface IAnimal
{
    name: string;
    type: string; 
}

function testAnimal(animal: IAnimal)
{
    alert('Name:'+animal.name)
}

var instance = {name: 'Gold Dragon', type:'dragon'};
var button = document.createElement('button')
button.innerText = 'Click me'
button.onclick = function(){
    testAnimal(instance)
}

document.body.appendChild(button)

One thing that attracts my attention is its interface usage. Interface in TypeScript is different than in C#. Here it doesn’t need to explicitly use keyword like extends, it just need to match the definition.

I haven’t tried this for my actual app, and I don’t have any plan yet. Most of the features from TypeScript can be imitated with pure JavaScript. We can use module loader like RequireJs, Browserify, etc to build modular system, we can use prototype based for inheritance, etc.

The fact is that we still need to learn JavaScript, at least for debugging, because if there is any error, we will still need to debug its generated JavaScript code.

Coming from C# background, TypeScript is definitely a good addition for our tools. I prefer it to CoffeeScript.