BT

TypeScript Release Adds Generics

by Jeff Martin on Jun 20, 2013 |

Microsoft has announced the release of TypeScript 0.9, and this release brings several new features, with the ability to use generics at the forefront.  TypeScript represents Microsoft’s attempt to make JavaScript better suited for large scale application development by incorporating type checking and static code analysis.

Highlights of the new features:

  • Generics support brings this popular feature to TypeScript, allowing for better type checking and modern programming patterns.
  • Overloading on constants
  • Support for use of “export = “ to support the direct importation of classes
  • Enums
  • TypeScript 0.9 – Redesigned to support future growth of the language.  Improvements have been made to better support incremental compilation, scale-up to larger codebases (100k+ lines), and fixes over 160 errors reported on CodePlex.

An interesting roundtable discussion with members of the TypeScript team, including Anders Heljsberg, Steve Lucco, and Luke Hoban was recently posted by Channel 9.  The conversation provided some additional insight into the new features of 0.9.  Hoban observed that TypeScript’s support for generics provides benefits even if they are not used directly by a programmer.  This is because TypeScript’s support for generics allows it to improve IntelliSense performance and assist with error checking.

Hejlsberg provided the following example during the discussion to demonstrate the changes from 0.8 to 0.9:

var a = [ “hello”, “world”, “….” ]

var n = a.map( s => s.length)

(where n is an array of numbers)

TypeScript 0.8:  s.   <- IntelliSense would show nothing

TypeScript 0.9:  s.   <- IntelliSense can show completions, including length

 

Hejlsberg also pointed out that TypeScript’s generics implementation is similar to Java’s, as opposed to C#.  This is in part because one of TypeScript’s goals is produce readable code.  So features like async support are not currently being developed by the team as the current limitations of JavaScript mean supporting this would produce overly complex code.  (IcedCoffeeScript was given as example of what the team was trying to avoid in TypeScript’s approach to code generation.)  Should JavaScript obtain support for iterators and generators, this would make it possible for TypeScript to provide async support and still produce human readable code.  Future updates to JavaScript may make this feasible.

Hello stranger!

You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT