Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News TypeScript 2.9 Release Updates ES.Next Support

TypeScript 2.9 Release Updates ES.Next Support

This item in japanese

TypeScript 2.9 contains several improvements to the language. Support is now available for ES.Next's import.meta, as well as symbols and numeric literals in keyof and mapped object types.

The ES.Next import.meta proposal is now a stage 3 proposal and expected for inclusion in ES2019. This feature allows a host environment to provide useful module-specific information for evaluation within a module. TypeScript 2.9 includes support for import.meta.

TypeScript program manager Daniel Rosenwasser identified the importing of types as a challenge before TypeScript 2.9:

One long-running pain-point in TypeScript has been the inability to reference a type in another module, or the type of the module itself, without including an import at the top of the file. In some cases, this is just a matter of convenience – you might not want to add an import at the top of your file just to describe a single type’s usage.

TypeScript 2.9 solves this problem. Instead of needing to import a module only to retrieve a type definition:

import * as _foo from "foo";

export async function bar() {
    let foo: typeof _foo = await import("foo");

Engineers may import the type as needed:

export async function bar() {
    let foo: typeof import("./foo") = await import("./foo");

Other changes in TypeScript 2.9 align with the ECMAScript standard. Trailing commas are no longer allowed on rest parameters as of TypeScript 2.9 to align with the ECMAScript standard. Type arguments are now available for generic tagged templates, making it easier to work with ES2015's template syntax.

Beyond ES.Next alignment, the TypeScript 2.9 release also improves the development experience with other environments including Node.js and React.

Node.js engineers expecting to use ES modules to import a JSON file may now do so when module resolution gets specified as Node, and the --resolveJsonModule flag gets set to true.

Users of React's JSX syntax are now able to parse and check type arguments on JSX opening and self-closing tags, a previous limitation with TypeScript's support for JSX.

The new --declarationMap flag, when combined with the --declaration flag, allows TypeScript to emit source map files with the output .d.ts files. TypeScript Language Services can then map declaration-file based definition locations to their original source.

Another significant addition for TypeScript 2.9 is support for symbols and numeric literals in keyof and mapped object types. The keyof operator predates TypeScript’s ability to reason about unique symbol types, so keyof never recognized symbolic keys.

TypeScript 2.9 changes the behavior of keyof to factor in both unique symbols as well as numeric literal types. As this is a breaking change, the --keyofStringsOnly flag reverts to TypeScript's pre-2.9 behavior.

One additional breaking change of note is that unconstrained type parameters are no longer assignable to objects when using the strictNullChecks mode because generic type parameters may get substituted with any primitive type.

Several improvements to diagnostics and language services are part of the TypeScript 2.9 release, as well as additional refactoring services such as the conversion of a private field to getter and setter notation, or the conversion of require in a TypeScript file to an ES import statement.

TypeScript 2.9 is available under the Apache 2 license via npm with the npm install -g typescript command. Contributions and feedback are welcome via the TypeScript GitHub project.

Rate this Article