Page 1 of 3
There is nothing like the thrill of you first few minutes with a new language and they don't come any newer than Microsoft's TypeScript. Find out what the fuss is about and if there is any point in using it.
TypeScript from Anders Hejlsberg
Before we get into the details of the language, we take a small detour into using it in Visual Studio. If you are only interested in the language then skip this section.
Getting started is fairly easy. You can just download the complier and use any text editor you like but the easiest way to get to know TypeScript is via Visual Studio and the special addin. The bad news is the addin doesn't support Visual Studio 2010; the good news is that it does work with the free Visual Studio Express 2012 for Web.
What all this means is that the simplest way to get a taste of what TypeScript is all about is to first download Visual Studio Express 2012 for Web and next install the Visual Studio plug in - http://www.microsoft.com/en-us/download/details.aspx?id=34790
Notice that this works on Windows 7 or Windows 8. If you want to try it with an earlier version then its the command line compiler and a text editor for you or point your browser at the TypeScript Playground where you can try small chunks of code out.
Once you have both installed you can start Visual Studio running and you should discover a new project type HTML Application with TypeScript in the Visual C# section. If you don't see it, and it seems to only appear after a full re-boot, then search for it (use the search box) and it should appear.
You will also discover that it supports a new file type - TypeScript ending in .ts. Use the File, New File and select Script and TypeScript File to add TypeScript to an existing project.
Three Key Language Ideas
There are three basic ways it does this.
- The first is that it introduces the module which allows you to encapsulate code in such a way that name collisions are avoided. It is essentially a cross between encapsulation and a namespace.
- The second is a standard class and inheritance based way of creating objects. You can define classes that inherit from other classes and instansiated objects using them.
- The third and final is the most radical. The type system that TypeScript introduces is partly based on type inference and some manual, optional, type annotation but the key introduction is the interface. TypeScript uses the interface to define an objects type. The interface creates a type system for objects.
Now lets take a closer look at each of the features.
Of the key ideas the module and the class are perhaps the simplest and hence least interesting but we need to know about them to describe the type system so let's begin with the module and then look at class.
If you are happy with the ideas of module and class simply jump to the section in the type system which is the real meat of TypeScript.