days
-3
-9
hours
-1
-5
minutes
-2
-8
seconds
-3
-9
search
JAX Developers Puzzle deadline approaching: Play for a chance to win a complimentary JAX London 2018 ticket!
New Types

TypeScript 1.6 is now live

JAX Editorial Team
Typewriter image via Shutterstock

Typescript is now available in version 1.6. The latest drop of Microsoft’s JavaScript extension brings about a handful of improvements, including support for React/JSX, the ability to write class expressions and new features in the Type system.

Just two weeks after the release of the beta version, TypeScript 1.6 is now available in its final incarnation. A summary of the changes has been put together by Jonathan Turner, Program Manager of the TypeScript team.

React with JSX Support

The React library had already been supplemented by the new .tsx file extension whilst in beta, with the last little deficiencies having now been ironed out. From hereon in, React brings full support for React typing and JSX. After taking into account a good amount of feedback from experts and the React team, issues of compatibility between the syntax for JSX and the casting syntax that uses TypeScript have been definitively eradicated.

The image below shows how TypeScript code and the JSX syntax easily coexist side by side. This allows TypeScript developers the possibility of mixing HTML-like code with TypeScript code.

© Microsoft

The React team commented on the changes as follows:

Our goal was to make it feel natural to work with React/JSX and to have all the type-checking and autocomplete capabilities of TypeScript.  This allows you a rich editing experience for working with React and JSX when using VS, VS Code, and Sublime.

Class expressions

Currently, the team are continuing to work on ECMAScript6 support in TypeScript, and the addition of class expressions is part of the process. Similar to class declarations, but they can also be used wherever an expression is. These in turn can be used in the extends clause:

class StateHandler extends class { reset() { return true; } } {
   constructor() {
     super();
   }
}

var g = new StateHandler();
g.reset();

What stands out in particular is that classes can be anonymous and may have still the same functions as class declarations.

Abstract classes

A long awaited feature is the support for abstract classes in TypeScript:

Similar in some ways to interfaces, abstract classes give you a way of creating a base class, complete with default implementations, that you can build from with the intention of it never being used directly outside of the class hierarchy.

This might look something like the following:

abstract class A {
  foo(): number { return this.bar(); }
  abstract bar(): number;
}

var a = new A();  // error, Cannot create an instance of the abstract class 'A'

class B extends A {
  bar() { return 1; }
}

var b = new b();  // success, all abstracts are defined

Improvements to module resolution

A number of improvements have been implemented for module resolution, too. The output of CommonJS should work just as well as NodeJS for the foreseeable future. If a module name is non-relative, TypeScript now follows these steps to find the associated typings:

  1. Check in node_modules for < module name >.d.ts
  2. Search node_modules\< module name >\package.json for a typings field
  3. Look for node_modules\< module name >\index.d.ts
  4. Then we go one level higher and repeat the process

Work on modules resolution will continue. In particular, the Asynchronous Module Definition (AMD) will be given up boost with forthcoming TypeScript versions.

The TypeScript team are keen to hear feedback and have promised more ES6 and ES7 features in future. A detailed overview of everything new can be found over at the TypeScript blog.

Leave a Reply

Be the First to Comment!

avatar
400
  Subscribe  
Notify of