Menu
What’s new in TypeScript 2.6

What’s new in TypeScript 2.6

TypeScript 2.6 introduces a new strict checking flag, error suppression comments, and "minor" breaking changes

Version 2.6 of Microsoft’s TypeScript language has moved to a release candidate stage. The new release of the typed superset of JavaScript features improvements such as increased strictness to help developers better find mistakes.

TypeScript 2.6 introduces a “strict” mode flag, which is identified as —strictFunctionTypes. In strict mode, any function type that does not originate from a method has its parameters compared “contravariantly,” Microsoft’s Daniel Rosenwasser, program manager for TypeScript, said.

TypeScript traditionally compared parameters in a “bivariant” manner, allowing for benefits such as a simpler model for working with arrays. TypeScript 2.6 offers a compromise of increasing strictness on all function types except methods while allowing TypeScript to continue modeling use cases including event handlers and simpler array handling.

TypeScript, which turned five years old on October 1, has been gaining in prominence, being used in the recent rewrite of the Angular JavaScript framework. Version 2.5 of TypeScript was released in late August, featuring extract method and extract function refactorings.

Other new features in TypeScript 2.6 include error suppression comments, which are introduced via // @ts-ignore comments. Microsoft has avoided error suppression within TypeScript because most cases where users asked for it could be solved through more accurate declaration files, or using a type assertion to “any,” Rosenwasser said.

“However, over time, we have seen two motivating examples,” Rosenwasser added, “migrating from JavaScript to TypeScript, and overcoming type checks that live in legacy code.” When migrating JavaScript to TypeScript, error suppression can help with a situation in which developers run into a pattern that is difficult to model. Developers could spend time trying to understand the pattern but may want to get of it later anyway. Now they can use suppression comments to avoid errors where code will still run fine.

For overcoming type checks in legacy code, some large organizations update project dependencies in tandem. Any change that introduces a type-checking error requires a fix to avoid breaking a build. “While the error is usually useful, the reality of the situation is that the code has functioned thus far and teams have finite resources,” Rosenwasser said. Microsoft advises using suppression comments sparingly, and always with an explanation.

Also new in TypeScript 2.6, tagged template strings within a module are now cached after the initial invocation. This move aligns TypeScript more closely with recent revisions to the ECMAScript specification underlying JavaScript. With this revision, developers can use libraries such as lit-html and hyperHTML

Several “minor” breaking changes are included in TypeScript 2.6, according to Microsoft. Various changes have been made to DOM declarations in lib.d.ts, and write-only references are now considered unused under —noUnusedLocals and —noUnusedParameters. Also, uninhabitable types that result from intersections such as number and string (”foo” & 42, for example) simplify to “never” when in a union.

TypeScript 2.6 RC can be accessed through NPM via npm install -g typescript@rc or through NuGet. It also can be installed through Visual Studio 2017.


Follow Us

Join the newsletter!

Error: Please check your email address.
Show Comments