TypeScript 2.4 improves load times, weak type-checking

Version 2.4 of TypeScript, a popular, typed superset of JavaScript, will offer improved load times with the addition of a dynamic import expressions capability. A release candidate version is now available via NuGet or via NPM, using the command npm install -g typescript@rc.

New TypeScript 2.4 features include dynamic import expressions, an ECMAScript feature that allows for asynchronously loading a module at any arbitrary point in a program. The capability results in faster load times for critical content, with less JavaScript being transmitted in many common scenarios. “Projects that use bundlers like Webpack can operate on these 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.

IDG Insider


« Google makes the best Android apps easier to find with Android Excellence


Hands-on: Microsoft's Xbox One X is a tiny console with big 4K gaming potential »
IDG News Service

The IDG News Service is the world's leading daily source of global IT news, commentary and editorial resources. The News Service distributes content to IDG's more than 300 IT publications in more than 60 countries.

  • Mail


Do you think your smartphone is making you a workaholic?