WHAT’S NEW IN TYPESCRIPT 2.6

What’s New in TypeScript 2.6

New in TypeScript 2.6

Microsoft’s TypeScript language is an added superset of JavaScript, designed to handle the needs of challenging programs worked on by there teams.

Microsoft’s TypeScript language is an added superset of JavaScript, designed to handle the needs of challenging programs worked on by there teams.

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 major reason for this upgrade to support both the JSX fragment syntax and properties named with const- declared symbols. An increased 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 of variadic functions.

WHAT’S NEW IN THE CURRENT VERSION TYPESCRIPT 2.6?

TypeScript 2.6 is presented as 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 as contravariant. TypeScript usually compared as a parameter in a “bivariant” manner, allowing for benefits such as a simpler model for working with arrays. TypeScript 2.6 offers an increasing strictness on all function types except methods.

ERROR SUPPRESSION COMMENTS WITH // @TS-IGNORE:

Traditionally, we have avoided error suppression within TypeScript because in most cases the users asked for it could be solved through more accurate declaration files, or using a type assertion to any.

For the prior one, the benefits are obvious: the developer wants to start moving over to TypeScript, but he/she has to run into a pattern that is particularly difficult to model. The developer might spend time trying to understand it, but maybe he/she would rather get rid of it later on anyway, so to just avoid errors because the code will still run fine.

The latter situation is a bit less clear. The impetus here was that within some large companies, dependencies across projects are updated in tandem, including TypeScript itself and @types declaration files from Definitely Typed. If any change is done the developer gets a type-checking error, someone has to fix that to elude the breaking build. But now a question arises: Who can do this?

The TypeScript 2.6 is bringing // @ts-ignore comments to TypeScript files. These comments suppress any errors that occur on the next line. For instance, in the following code, TypeScript would ordinarily report an error about the console.log statement being unreachable. In TypeScript 2.6, the // @ts-ignore comment flattens the error entirely.

if (false) {

// @ts-ignore: Unreachable code error

console.log(“hello”);

}

BREAKING CHANGES AND DEPRECATIONS

There are several minor changes that may impact the codebase.

Write only references are now considered unused under — noUnusedLocals and –noUnusedParameters.

In ambient contexts such as declaration files, and declare module blocks, expressions are now rejected in defaultexports.

Uninhabitable types resulting from intersections will simplify to never when placed in a union.

Various changes have been made to DOM declarations in lib.d.ts.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>