What’s new in TypeScript 2.6

What’s new in TypeScript 2.6

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.

The new features in TypeScript 2.6

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:

  • Tagged template strings in 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.
  • The standalone TypeScript compiler now offers localized messages over NPM when using the --locale flag.
  • The --watch mode, for emitting modules, has been made faster.
  • Tool support improvements are planned for tools such as Visual Studio and Visual Studo Code, including quick fixes for anys, with TypeScript able to infer types for declarations with types that are an implicit any.
  • Developers will be able to refactor JSDoc documentation comments to TypeScript annotations.
  • Editors will soon be able to offer a quick fix to install type declarations for untyped imports.
  • TypeScript 2.6 has some breaking changes, such as write only references being considered unused under —noUnusedLocals and --noUnusedParameters.
  • Organizational changes have been made to DOM declarations in lib.d.ts.
  • in ambient contexts, such declaration files and declare module blocks, expressions are disallowed in default exports.
  • Write-only references are now considered unused under --noUnusedLocals and --noUnusedParameters.
  • Uninhabitable types that result from intersections such as number and string (:"foo" & 42, for example) simplify to never when in a union.

What’s next in TypeScript 2.7

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.

Where to get TypeScript

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.

Source: https://www.infoworld.com/article/3233272/javascript/whats-new-in-typescript-26.html#tk.rss_news

Powered by WPeMatico