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.

typescriptlogo

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.

typescriptlogo

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.

 

Banner


Google Updates Responsible AI Toolkit
01/11/2024

Google has announced updates to the Responsible Generative AI Toolkit to enable it to be used with any LLM model. The Responsible GenAI Toolkit provides resources to design, build, and evaluate open A [ ... ]



Visual Studio 17.12 Released Along With Aspire
25/11/2024

Visual Studio 2022 v17.12 is now available. The release can be used for .NET 9 projects and has a range of other improvements.


More News

 

espbook

 

Comments




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

Last Updated ( Tuesday, 31 July 2018 )