What's New in TypeScript 3.2 Release Candidate
The next edition of the popular language includes tweaks affecting binding, working with generics and new BigInt functionality.
For generics, TypeScript now allows for using "spreads" on generic types, using the spread operator ("..."), which lets an iterable expand in places where arguments are expected, allowing, for example, taking an object like an array and expanding it into a set of items that can be copied into another array.
"TypeScript does a pretty good job here when it has enough information about the type," Microsoft's Daniel Rosenwasser said in a post yesterday. "The type system closely tries to model the behavior of spreads and overwrites new properties, tries to ignore methods, etc. But unfortunately up until now it wouldn’t work with generics at all."
This complex problem was solved after a lot of thought, but the end result is "TypeScript 3.2 now permits object spreads on generics and models them using intersections."
Generics can also be used with the object rest pattern, which is akin to spreads in that it creates a new object wherein certain properties are excluded. The team figures out how use rest with generic objects.
The new edition also provides stricter checking for bind, call and apply, described by Rosenwasser as "methods on functions that allow us to do things like bind this and partially apply arguments, call functions with a different value for this, and call functions with an array for their arguments."
The team figured out how to model these patterns in a type-safe way, with the upshot being a mechanism to "ensure our uses of bind, call, and apply are more strictly checked when we use a new flag called strictBindCallApply."
"TypeScript 3.2 brings type-checking for BigInts, as well as support for emitting BigInt literals when targeting esnext," Rosenwasser said. "BigInt support in TypeScript introduces a new primitive type called the bigint (all lowercase)." He emphasized that BigInt support is only available for the esnext target (indicating a future version of ECMAScript yet to be released).
Coincidentally with yesterday's announcement of TypeScript 3.2 RC, GitHub also published a post examining what makes programming languages popular, in which it noted the fast rise of TypeScript.
"TypeScript entered the top 10 programming languages for public, private, and open source repositories across all regions last year," GitHub said.
GitHub is also the place where you can go to find out what features are planned for future versions of TypeScript in the roadmap.
David Ramel is an editor and writer for Converge360.