TypeScript adds Dynamic Import Expressions
TypeScript 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.

More Informationtypescriptlogo

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, FacebookGoogle+ or Linkedin.

 

Banner


Visual Studio Code Comes To Raspberry Pi And Chromebooks
14/07/2017

A new community build of Visual Studio Code has made the lightweight source code editor available for Chrome OS and Linux running on Raspberry Pi boards and Chromebooks.



Apache Spark With Structured Streaming
21/07/2017

Apache Spark 2.2 has been released with Structured Streaming no longer experimental. The accompanying release of PySpark is also available in pypi.


More News

 

 
 

 

blog comments powered by Disqus

Last Updated ( Tuesday, 04 July 2017 )
 
 

   
Banner
RSS feed of news items only
I Programmer News
Copyright © 2017 i-programmer.info. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.