TypeScript- A new Microsoft cross-platform JavaScript Language
The article describes about the new scripting language which is superset of the existing JavaScript language. It also describes about the features of TypeScript, its usage and a simple example to use in the Visual Studio IDE.
TypeScript- a new cross-platform JavaScript language
The TypeScript Language is developed by developer and lead Anders Hejlsberg (famous for creation of languages like Turbo Pascal, Delphi, and C#).
TypeScript has been released on 1st Oct '12.
TypeScript is having the light weight setup of 3.7 MB which can be downloaded from the below link:
http://www.microsoft.com/en-us/download/details.aspx?id=34790
TypeScript is the Open Source cross-platform JavaScript language developed by Microsoft Organization.
It is used for the client side scripting with additional features as compare to JavaScript and VB Script.
TypeScript extends JavaScript syntax, so any existing JavaScript programs work with Typescript without any changes.
Hence we can say that the TypeScript is the superset of the JavaScript with true Object Oriented features and strongly typed.
TypeScript is mainly designed for development of large applications where the JavaScript is not suitable. While compilation of TypeScript, it produces the JavaScript which can be used for the backward compatibility.
TypeScript language basically extend the JavaScript features and supports the cross platforms.
It can run on any browser or any devices which are capable to run the JavaScript. So we can say that the TypeScript is browser and platform independent.
This TypeScript language is basically created for large applications where JavaScript fails or does not supports well. Using the TypeScript we can write the client side code for large scale applications.
Here large application or large scale application means that the application pages in the browser contains lot of data manipulation as well as the loading of lot of data (maintaining the large data in browser screen).
To maintain the large data on the browser window, the developer needs lot of effort to maintain it.
In terms of functionality of the page, the new scripting language (TypeScript) uses the similar syntax and semantics as the previous scripting language- JavaScript. It compiles to clean, standard, broadly compatible JavaScript.
In the real sense, the TypeScript is the JavaScript with additional functionality which can handle the client side scripts for large-scale web client applications to the same JavaScript standard. By this, the developers can use the same existing JavaScript with additional capabilities.
So we can say that the TypeScript is the superset of JavaScript. The new language TypeScript will combine the type checking and static analysis, explicit interfaces etc as the single language with compiler.
The JavaScript is lacking with some features of Object oriented languages like there is no built-in module system. JavaScript is lacking to create the interfaces similar to C# and Java language. Also there is no static type checking at compile time etc.
The TypeScript is released for the Visual Studio 2012 as a Plug-in, with the hope that it will improve the developer's experience to build the large scale JavaScript applications. This TypeScript plug-in will be used for code navigation, refactoring, static error messages, and IntelliSense etc.
There are many other scripting languages similar to JavaScript which are used for scripting in the web application are:
CoffeeScript ? JavaScript + Object Oriented Capabilities
Script# ? Java + C#
Emscripten ? Supported by LLVM compiler toolkit
JSIL ? compiles .NET programs into JavaScript.
The TypeScript language has taken the concepts from other languages like Dart (from Google) and having the similar structure like the JavaScript.
So instead of discarding the JavaScript syntax, TypeScript extends the JavaScript syntax.
The TypeScript language is very conservative language which is having the limited type inference.
Visual Studio 2012 has the plug-in available for TypeScript. It includes static error messages, code navigation and refactoring with all other benefits.
As per the Somasegar comments "TypeScript is fully standards compliant and completely cross-platform, being operating system and browser agnostic".
New language for application-scale JavaScript development
According to the Anders Hejlsberg "TypeScript is really about starting with JavaScript and then strengthening it with the features that are lacking for application-scale development and then building excellent tooling around those capabilities."
So now what we can say about the difference between the TypeScript and JavaScript-
TypeScript is the scaled version of JavaScript or we can say that TypeScript is large scaled JavaScript which can support media rich HTML5 features.TypeScript: Enhanced version of JavaScript
TypeScript Features:
1. Type annotations
The language TypeScript provides the strong typing through type annotations. It enables the type checking at compile-time.
function Add(left: number, right: number): number {
return left + right;
}
The annotations for the primitive types are number, bool and string. Weakly, or dynamically, typed structures are of type Any.
If there is no type declaration in the TypeScript, it will take as the weak type.
2. Support of ECMAScript 6
TypeScript includes the features of the ECMAScript 6 standard. It includes
• Classes (with inheritance)
e.g. class Person {
private name: string;
private age: number;
constructor(name: string, age: number) {
this.name = name;
this.age = age;
}
toString(): string {
return this.name + " (" + this.age + ")";
}
}
• Modules
• Arrow functions
3. Generics support
The TypeScript will also support the Generics in the future as the Microsoft.
4. JavaScript Compatibility
As the TypeScript is superset of JavaScript. The application developed using the TypeScript can consume the existing JavaScript scripts and vice versa. Also the compiled TypeScript can be consumed by JavaScript.
The existing scripting frameworks like JQuery is also support by TypeScript language.
5. Platforms and Web browser support
As the TypeScript languages is the Cross Browser and Cross platform so any web browser on any of the platform can run TypeScript. The reason is that it is nothing but the compiled JavaScript.
6. TypeScript Compiler
The compiler for TypeScript named as tsc is written in JavaScript, which consumes the TypeScript and compiled the code in to JavaScript and executes in Any web browser on any platform. By default the current version target of the compiler supports is ECMAScript 3.