Start United States USA — software What’s new in TypeScript 2.6

What’s new in TypeScript 2.6

478
0
TEILEN

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 the 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,” said Microsoft’s Daniel Rosenwasser, program manager for TypeScript.
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 letting TypeScript continue modeling use cases such as 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 .
Another key set of new features in TypeScript 2.6 covers error suppression comments, which are introduced via // @ts-ignore comments. Microsoft has avoided error suppression in 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 in TypeScript 2.6:
TypeScript 2.7 is due in January 2018, and will feature improved type inference for object literals. The upgrade also is slated to support both the JSX fragment syntax and properties named with const- declared symbols. An incremental builder compiler API is also planned.
At some point perhaps beyond TypeScript 2.7, the language is slated to support project references and provision of specific types to variadic functions.
TypeScript 2.6 can be accessed through NPM via npm install -g typescript@rc or through NuGet. It also can be installed through Visual Studio 2017.

Continue reading...