Microsoft Introduces TypeScript, a Strict Superset of JavaScript

Microsoft TypeScriptJavaScript is a familiar programming language to developers and its one of the languages that developers can use to make Windows 8 apps. In October 1st, 2012, Microsoft announced a new programming language it calls TypeScript that is designed to extend the features of the familiar JavaScript.

TypeScript that is a strict superset of JavaScript, adds optional static typing and class-based object-oriented programming.

TypeScript is created for developers to develop large-scale JavaScript applications. The people behind the language at Microsoft have said that internal as well as external customers expressed problems structuring their code in JavaScript. TypeScript is meant to solve that issue.

Microsoft has dealt with challenges that complex JavaScript code is demanded for custom tooling to ease the writing of components. The company stated that they didn't have the intention of making something that could break compatibility with the standard and its cross-platform support. Knowing that the current ECMAScript standard proposal would bring support for class-based programming, Microsoft decided to build on that proposal. This led to a superset that transforms the extensions into regular JavaScript.

In a post, S. Somasegar, Microsoft's Vice President of the Developer Division, talks about the growth of JavaScript among developers. Microsoft's plan with TypeScript it to make it easier for developers to create large scale JavaScript-based applications.

"TypeScript is a superset of JavaScript that combines type checking and static analysis, explicit interfaces, and best practices into a single language and compiler. By building on JavaScript, TypeScript keeps you close to the runtime you're targeting while adding only the syntactic sugar necessary to support large applications and large teams. Importantly, TypeScript enables great tooling experiences for JavaScript development, like those we've built for .NET and C++ and continue to innovate on with projects like 'Roslyn'. This is true whether you’re writing client-side JavaScript to run on Windows, Internet Explorer, and other browsers and operating systems, or whether you're writing server-side JavaScript to run on Windows Azure and other servers and clouds."

Microsoft states that all codes written in JavaScript works with TypeScript. An example is shown in the "hello, world" example above where the code on the left side is in JavaScript but treated as TypeScript. The code on the right contains the output of the TypeScript compiler for this code.

The TypeScript compiler, named tsc, can be compiled into regular JavaScript that can be executed in any JavaScript engine in any host. The compiler package is bundled with a script host that can execute the compiler. It's also available as a Node.js package that is using Node.js as a host. There is also an alpha version of a client-side compiler in JavaScript, which executes TypeScript code on the fly, upon page load.

TypeScript compiles to ES3-compatible JavaScript. By default, the compiler targets ECMAScript 3, and is also able to generate constructs used in ECMAScript 5.

With TypeScript, developers can use existing JavaScript code, incorporate popular JavaScript libraries, and call TypeScript-generated code from other JavaScript. Type declarations for these libraries are provided with the source code.

Microsoft has also made TypeScript an open source language. "The TypeScript language is made available under the Open Web Foundation’s Final Specification Agreement (OWFa 1.0), and we invite the community to discuss the language specification," said Somasegar.

TypeScript provides third-party header files for popular libraries like jQuery, MongoDB, Node.js, and D3.js.

"I personally am super excited about what the impact of TypeScript can be on the world of software development, particularly in a world where there is so much momentum for the web programming model. This is another important step in the journey for great tools for standards web development from Microsoft," ends Somasegar.