TypeScript 2.4 improves load times, weak type-checking

Posted on 13-06-2017 , by: admin , in , 0 Comments

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.