What’s new in TypeScript 2.6
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.
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.
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:
- The standalone TypeScript compiler now offers localized messages over NPM when using the
--watchmode, 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
- 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 —
- Organizational changes have been made to DOM declarations in lib.d.ts.
- in ambient contexts, such declaration files and
declare moduleblocks, expressions are disallowed in
- Write-only references are now considered unused under
- Uninhabitable types that result from intersections such as number and string (
:"foo" & 42, for example) simplify to
neverwhen 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
Where to get TypeScript
Powered by WPeMatico