What’s new in TypeScript 2.7

Highlights of the forthcoming release of the JavaScript superset include fixed length tuples definite assignment checks for class properties

Credit: Mira DeShazer

Microsoft has moved TypeScript 2.7 to a release candidate stage, with general availability of the new version expected in a few weeks. TypeScript 2.7 brings three noteworthy improvements: definite assignment checks for class properties, fixed length tuples, and improved narrowing for the in and instanceof operators. 

With fixed length tuples, Microsoft notes, “tuple types now encode their arity [i.e. the number of elements they include] into the the type of their respective length property, and tuples of different types are no longer assignable to each other.” This is a breaking change.

TypeScript 2.7 also is slated to add refactoring of the CommonJS module to ECMAScript 6, with this being the version of the standard JavaScript specification approved by ECMA International in 2015.

New TypeScript features

Other new capabilities in TypeScript 2.7 include:

  • Definite assignment checks for class properties. A new flag, --strictPropertyInitialization, performs checks to ensure that each instance property of a class is initialized in the constructor body or by a property initializer. A compiler option, this flag will be turned on with other --strict mode flags. To turn off this checking, developers can set the --strictPropertyInitialization  setting to false in tsconfig.json’s compilerOptions, or --strictPropertyInitialization false on the command line.
  • Improvements related to narrowing for in and instanceof operators. The in operator now acts as a narrowing expression for types, with types narrowed out that do not explicitly declare properties of a given name. The instanceof operator now leverages the inheritance chain, rather than relying on structural compatibility. This more accurately reflects how instanceof may behave at runtime.
  • Definite assignment assertions, in which a variable or property declaration can include a definite assertion in the form of a “!” character after the variable or property identifier. This assertion instructs the control flow analyzer to consider the variable definitely assigned, even if the analyzer cannot prove it.

The 2.7 release follows the Halloween release of TypeScript 2.6, which helped developers better locate mistakes in code.

Download TypeScript 2.7

You can download TypeScript through NuGet or via npm. To get the TypeScript 2.7 release candidate via npm, use the following command: npm install -g typescript@rc.

Join the newsletter!

Or
Error: Please check your email address.

More about ECMAMicrosoft

Show Comments
[]