TypeScript 2.4 Adds Dynamic Import Expressions
Written by Ian Elliot   
Tuesday, 04 July 2017

There's a new version of TypeScript with support for dynamic import expressions, string enums, and weak type detection. 

TypeScript was developed by Microsoft ,and is a superset of JavaScript that builds on the ECMAScript standard and includes support for static types. Your TypeScript code then gets transformed into clean, runnable JavaScript.


TypeScript 2.4's main improvement is the support for dynamic import expressions. These are ECMAScript’s new import calls, which import a module and return a promise to that module. The example given is that of a webpage that allows you to create and edit images, where you want to download multiple images in a zip file. If you chose to load the functionality to download multiple files lazily,  import() expressions let you load a module on the fly as a Promise. In other words, you can send less JavaScript over the wire for more common scenarios, so achieving faster page load times for critical content, but still providing the more unusual options.

Safer callback parameter checking is another area of improvement. This means that when internal data is handed off through callbacks – specifically, Promises,

When checking whether two functions are assignable to one another, TypeScript checks whether their parameters are bidirectionally assignable. We call this function parameter bivariance. There are a number of reasons for this, but it mainly stems from TypeScript’s structural nature and how we’ve tried to match people’s intuition.

Our experience has been that users generally don’t run into issues with this all that much; however, we did start to see that this model broke down on containers which handed internal data off through callbacks – specifically, Promises, TypeScript compares the parameters that are callbacks, and identifies problems where code is attempting to assign incompatible parameters.

Checking for weak types has also been added.  Any type that contains only optional properties is considered a weak type since it provides few restrictions on what can be assigned to it. In TypeScript 2.4, it’s now an error to assign anything to a weak type when there’s no overlap in properties. The developers say that you can think of this as TypeScript “toughening up” the weak guarantees of these types to catch what would otherwise be silent bugs.

The final major improvement is support for string enums. Enums have been provided since early versions of TypeScript to mark sets of related numeric values. This latest release has added string enums, so your enum members can contain string initializers.


More Information

TypeScript On GitHub

What's New In TypeScript 2.4

Related Articles

TypeScript 2.3 Released

TypeScript 2.2 Adds More Code Actions

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.



Apache Releases NetBeans 22

Apache NetBeans 22 has been released. This release has a new Gradle Wizard, upgrades to Java 22 javac, and a number of UI changes.

Eclipse Releases Theia IDE

The Eclipse Foundation has released Theia IDE, which they say is created for developers seeking a modern, open, and flexible tool for their coding pursuits. The IDE is based on the Theia Platform, whi [ ... ]

More News


kotlin book



or email your comment to: comments@i-programmer.info

Last Updated ( Tuesday, 31 July 2018 )