npm install -g typescript@rc.
import() calls and split code into smaller bundles that can be lazily loaded,” said Daniel Rosenwasser, Microsoft’s program manager for TypeScript.
Also featured in version 2.4 is a check for weak types, which contain only optional properties and have few restrictions on what can be assigned to them. Microsoft wants to strengthen weak guarantees of these types to catch silent bugs. “In TypeScript 2.4, it’s now an error to assign anything to a weak type when there’s no overlap in properties,” Rosenwasser noted. The new check for weak types will cause code to break, so developers will need to declare properties that exist, add an index signature to a weak type, and use a type assertion.
TypeScript 2.4 also offers safer callback parameter checking. “TypeScript will be strict about checking parameters contravariantly with respect to the current check,” Rosenwasser said. The impetus for this change was that TypeScript would check whether parameters are bidirectionally assignable; although this check generally has not caused any issues, this model did break down on containers that handed internal data from callbacks.
Improved inference for generics changes how generics are inferred. TypeScript currently can, for example, make an inference for the return type of a call, which can improve the experience and also catch errors. Version 2.4 also now allows
enum members to contain string initializers. TypeScript has supported both string literal types and enums, but users wanted some enums to do some of what string literals can do; the new string enums are the result of this desire, Rosenwasser said.