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


AWS Adds Support For Llama2 And Mistral To SageMaker Canvas
12/03/2024

As part of its effort to enable its customers to use generative AI for tasks such as content generation and summarization, Amazon has added these state of the art LLMs to SageMaker Canvas.



WasmCon 2023 Sessions Now Online
01/03/2024

The recorded session of the premier conference for technical developers and users interested in exploring the potential of WebAssembly are now online.


More News

 

raspberry pi books

 

Comments




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

Last Updated ( Tuesday, 31 July 2018 )