TypeScript 2.3 Released
Written by Ian Elliot   
Tuesday, 02 May 2017

The latest release of Microsoft’s open source typed superset of JavaScript is now available. TypeScript 2.3 features generators and iteration for ES5/ES3, generic parameter defaults and more. 


typescriptlogo

According to Daniel Rosenwasser, writing on the MSDN Blog, 

Previously, TypeScript didn’t support compiling generators or working with iterators. With TypeScript 2.3, it not only supports both, it also brings support for ECMAScript’s new async generators and async iterators.

The difference between AsyncIterator and Iterator is that the nextreturn, and throw methods of an AsyncIterator return a Promise for the iteration result, rather than the result itself. This allows the caller to enlist in an asynchronous notification for the time at which the AsyncIterator has advanced to the point of yielding a value. An AsyncIterator has the following form:

TSasynciterator

TypeScript 2.3 adds support for declaring defaults for generic type parameters, which can eliminate a lot of typing. A generic parameter default follows the following rules:

 

  • A type parameter is deemed optional if it has a default.

  • Required type parameters must not follow optional type parameters.

  • Default types for a type parameter must satisfy the constraint for the type parameter, if it exists.

  • When specifying type arguments, you are only required to specify type arguments for the required type parameters. Unspecified type parameters will resolve to their default types.

  • If a default type is specified and inference cannot chose a candidate, the default type is inferred.

  • A class or interface declaration that merges with an existing class or interface declaration may introduce a default for an existing type parameter.

  • A class or interface declaration that merges with an existing class or interface declaration may introduce a new type parameter as long as it specifies a default.

For Rosenwasser, a new type checking mode using comments to specify types on regular JavaScript declarations. comes top of the list of the new features. He writes:

TypeScript has long had an option for gradually migrating your files from JavaScript to TypeScript using the --allowJs flag; however, one of the common pain-points we heard from JavaScript users was that migrating JavaScript codebases and getting early benefits from TypeScript was difficult. That’s why in TypeScript 2.3, we’re experimenting with a new “soft” form of checking in .js files, which brings many of the advantages of writing TypeScript without actually writing .ts files.

Instead, all you need to do to type-check a file is to add a comment with // @ts-check to the top.

Rosenwasser also explains how TypeScript 2.3 makes it easier for getting  started with Typescript and discovering its features. This comes as a response to finding that  people were often unaware that TypeScript could work on JavaScript files, or that it could catch nullability errors. To make TypeScript more accessible, help output has been improved so that options are grouped by their topics, and more involved/less common options are skipped by default and init output lists potential options in comments.

To provide optimal developer experience TypeScript 2.3 introduces a new --strict flag which will be turned on by default for all new projects started with tsc --init. It enables the following settings:

TSstrict

 

 

 

 

 

 

The final of these enforces JavaScript strict mode in all files.

 

According to the TypeScript Roadmap, the next release of the language, version 2.4, will include covariant checking for callback parameters, string enums, refactoring support in Language Service API, and better error reporting.

typescriptlogo 

More Information

What's New In TypeScript

Announcing TypeScript 2.3

TypeScript Roadmap

Related Articles

TypeScript 2.2 Adds More Code Actions

TypeScript 2.0 Adds Null, Undefined And Never  

TypeScript 1.8 Hits Beta

TypeScript Goes Light, Moves To GitHub 

TypeScript Fully Accepted into Visual Studio 

 

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


Explore SyncFusion's Blazor Playground
16/04/2024

Syncfusion has provided an in-browser environment where you can write, compile and run code that uses Blazor components and get it previewed live.



Conference Times Ahead
29/03/2024

Following a well-established pattern both Google's and Microsoft's Developer Conferences will take place in May while Apple follows on in June. Here are the dates plus what to expect.


More News

raspberry pi books

 

Comments




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

 

Last Updated ( Saturday, 19 August 2017 )