TypeScript 3.6 beta coming out with stricter checking for iterators and more

TypeScript 3.6 beta coming out with stricter checking for iterators and more

Now, Microsoft has released the first beta for version 3.6 of the TypeScript JavaScript superset with stricter checking for iterator and generator.

TypeScript 3.6 provides stricter checking for iterator and generator functions, a more accurate array spread, and improved the user experience when using promises.

 

This version is considered as a feature-complete, so it should compile new features for the upcoming release. There are only bug fixes and performance improvements will follow in the coming updates.

 

In previous releases, developers have had no way of distinguishing whether value comes from a yield or return when using a generator. Generator always assumed that the type of yield is any. To change that, the development team of TS has added some type parameters and a new generator type to iterator and IteratorResult. This allows Iterator developers to specify the yield and return type and determine which type to accept next.

Based on this, the new generator Tp is an iterator in which the methods return and throw are always present. To allow the distinction between return and yield values, the IteratorResult type now converts to a discriminated union type.

 

This beta also includes more accurate array spreads. TS 3.6 uses a simple emit for array types for for-of loops and array spreads for ECMAScript versions before ES2015, as well as a downlevelIteration flag for other types. Using the flag, the output code is much larger but more accurate. With this, many users rely on simple emit, but in some special cases led to strange issues.

 

In TS 3.6 beta, developers can use the helper __spreadArrays, which should be more accurate when dealing with ECMAScript 2015 and earlier.

 

According to the dev team, promises are one of the most popular ways to work with asynchronous data. Though, the use of an API based on Promises is often confusing to users. But, this new beta version offers some improvements intended to curb the misuse of promises. The error notification now more accurate, and it warns users to possibly build an await.

 

TypeScript tweeted,


 

If everything goes right, TypeScript 3.6 should appear as a full release by the end of August, as the TypeScript team said.

 

You can get more details of new features on the official blog post.

News Source

Recommended for you