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
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.
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
strictmode flags. To turn off this checking, developers can set the
strictPropertyInitializationsetting to false in t
--strictPropertyInitializationfalse on the command line.
- Improvements related to narrowing for
inoperator now acts as a narrowing expression for types, with types narrowed out that do not explicitly declare properties of a given name. The
instanceofoperator now leverages the inheritance chain, rather than relying on structural compatibility. This more accurately reflects how
instanceofmay 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.