BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News TypeScript Release Adds Generics

TypeScript Release Adds Generics

This item in japanese

Lire ce contenu en français

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
Style

BT