BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

TypeScript Release Adds Generics

| by Jeff Martin Follow 5 Followers on Jun 20, 2013. Estimated reading time: 1 minute |

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.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login 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

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and don't miss out on content that matters to you

BT