Paul Krill
Editor at Large

What’s new in Microsoft’s TypeScript 2.4

news
Jun 13, 20172 mins

Support for dynamic import expressions is among the new features in the release candidate now available

typewriter typescript
Credit: Mira DeShazer

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.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author