TypeScript: transition language to the future JavaScript

This new language from Microsoft brings main features of ECMAScript 6 and 7, without waiting for their implementation in browsers.

This is the first programming language whose use is intended to be temporary. Thanks to a syntax similar to JavaScript and because it is compiled into this language, it is possible, once the additional functions that it brings will all be implemented in the interpreters, to replace the TypeScript code by the JavaScript code. Generated by the first or unchanged.
So developers could skip the step of compiling to JavaScript code and TypeScript then will disappear! This is different from that is proposed by Dart, which offers the same features but wants to replace JavaScript in browsers.
It is a superset of JavaScript: we can taje is code written in the latter, make a TypeScript source and add classes and interfaces.

Typescript is used in production with always positive returns, because it greatly improves productivity, and one never want to return to JavaScript. The only significant drawback is the slow compilation on big projects. It is the programming language of Angular 2 (from Google).

The compiler is open source under the Apache license and built with Node.js and Jake, a kind of Make for projects designed to JavaScript, where makefiles are replaced by jakefiles. The source code itself is written in TypeScript, and converted into a single file, TypescriptServices.js (the compiler), so it uses the V8 interpreter from Google!
The executable code is not provided directly to download (you can produce it yourself) but as part of Visual Studio 2013 or as npm module.

TypeScript vs JavaScript
The playground shows how the TypeScript code becomes JavaScript

Static types

The syntax var x: boolean can annoy at first. Writing number x or bool x as in C would have been simpler. Following this logic, instead of writing class x why not write definition x: class?
But this is nevertheless justified here by the optional types: we can write var x and have a dynamic variable whose type can change during processing, or add a static type. The type is clearly an option, and this syntax is in line with Asm.js or Julia.

The language implements the following types:

Functions

A function can have generic arguments by overload or through union.
Example of union:

function(s:string | string[]) 

Classes and interfaces

The syntax for declaring a class is similar to that of ECMAScript 6 and in fact most of programming languages. We define the constructor with the reserved word constructor, and this is added to reference an attribute in the class.

For example:

class car {
  passengers = 4;
  constructor(persons : number) {
    this.passengers = persons;
  }
  
  mymethod(message : string) {
    console.log(message);
  }
}

var mycar = new car(2);

Inheritance is done with the extends keyword:

class car extends vehicle { ... }

The constructor may call the constructor of the inherited class with super(...).
Attributes are public by default, we need only a private keyword to declare a member as private.
The reserved word static can be applied to class members to share values ​​assigned between all inherited classes.

Inheritance is translated into JavaScript with prototypes while other elements are used only to control by the compiler and are not converted. It is probable that the language will evolve to a more accurate translation when ECMAScript will be widely implemented.

Classes may be associated with interfaces. Example:

class motor extends car {
  power : number;
}
interface car {
  passengers : number;
}

var mycar : car = { passengers : 4, power : 300 };

TypeScript therefore has both inheritance and composition, that ​​Go and Dart for example do not offer. Unfortunately it does not seem more intended for ES 6 and may force you to stay on TypeScript if you actually use this feature, because this can be extremely useful for reusability of code.

Other additions

I will not detail all the features of TypeScript, which are described in detail with examples in the documentation on the site, but here is an overview of other possibilities of the language.

Missing functions

Some features from ECMAScript are already implemented in browsers are not mentioned in the latest TypeScript specification:

Why use typescript?

Typescript is becoming increasingly popular, as evidenced by Google Trends statistics:

TypeScript vs others

The advantage of typescript on all the other languages that are compiled into JavaScript is that it is a superset: You can reuse a JS file and include features added in typescript, and then rename the file from .js to.ts.
And when the language introduces new features, they come from ECMAScript 6 and followers, so it remains a superset of JS.

Typescript seems indispensable for a large JavaScript project. The code generated is optimized for JIT interpreters. Code reusability is greatly facilitated. And we do not fear for the future, even the source code is easily reusable without the compiler. It has shortcomings, but it can be addressed by combining JavaScript code with the TypeScript inheritance. It will not solve all the problems of JS because JS problems are not inherent to him, they are in browsers, DOM or misuse of the language.
What it solves essentially is the reusability of code. And it saves us from the use of Dart which would fragment web programming.

TypeScript. The official site. The language was created by Anders Hejlsberg who is also the author of Turbo Pascal, C#.
The authors of the manual have made ​​a special effort to help learn the language: each example can be viewed in the playground where it can be modified, and is converted into JS.

Download the compiler as add-on to Visual Studio. You can get it as module to Node: npm instal l-g typescript.
The language is supported beside VS by Eclipse and various commercial IDEs.

Playground. Test live translation of a TypeScript program in JavaScript.

Programming and data languages Asm.js - Basic - C - C++ - C# - Dart - Go - Java - JavaScript - Julia - Pascal - PHP - Prolog - Python - Ruby - Rust - Scala - Scriptol - Swift - TypeScript - HTML - Wasm - XML - XAML - SQL