TypeScript Benefits

I just started reading the basics of Typescript and can anyone tell me the benefits of using Typescript over Javascript or jquery? Some example would be helpful.

+7
source share
3 answers

I used typescript for several small hobby projects, and I am convinced that this is the perfect Javascript replacement. My favorite features were:

  • Declaration files. With declaration files, you can add type information to your javascript libraries. This structured information will provide you with fantastic Intellisense support in VisualStudio.

  • "Standard" OOP. If you work against C # or Java, you probably won't even need a typescript tutorial. It just works. You have classes, interfaces, access modifiers, extension mechanisms, ...

  • Built-in module support. typescript has a slightly confusing modular system. You can split your code into several .ts files and just add them, but you can also create different modules.

And finally: Syntax. Sometimes these are the little things that have the greatest impact. The typescript syntax seems just perfect to me. Let me give you some examples:

Enter annotations labeled ":" and enter

var a = 5; //infers that a has the type number var canvas : HTMLCanvasElement = document.getElementById("canvas"); // automatically casts to the canvas type. Intellisense will now suggest all the canvas specific methods 

Arrays that work like lists, stacks, ...

 var array= []; //dynamic type array.push(1); array[1]=2; array.pop(); var array2 : number[] = []; //typed array array[0]=2; array[1]="hello" //compile time error. You've got to love the type system. Finally you can trust your collections 

And functions with arrow syntax like lambdas:

 var array=[]; array.push(1); //... array.forEach((num)->{alert(num);}); //for single statement functions you can write array.forEach((num)->alert(num)); 

Arrays and lambdas are now typed together:

 var array: number[]=[]; array.push(1); //... //let assume you want to work with the data in the array. You've got to filter it and process it. Lambdas will come in handy, as well as the type inference array.filter((num)->num>3).map((num)->num*2).forEach((num)->alert(num)); // the first lambda with the comparison is fully type safe. The compiler knows the type of the array. Therefore it can infer the type of the parameter num and will check if num can be compared to a number 

I really enjoyed using typescript. This will greatly increase your productivity. And more to come: http://typescript.codeplex.com/wikipage?title=Roadmap

In release 0.9, shared files will be introduced, and for versions 1.x they plan to implement async / wait calls.

+11
source

JQuery and Typescript are not mutually exclusive, as JQuery is often used in Typescript. The main benefit of using Typescript over Javascript is the addition of type checking. This allows you to create interfaces and develop on a contract basis. In larger projects, it is useful to have type checking, but this is a subjective preference.

+3
source

Here's a collection of TypeScript videos:

http://channel9.msdn.com/search?term=typescript

It basically adds optional static input to Javascript, so all the benefits of static input are brought into Javascript.

+2
source

All Articles