TypeScript 3.6 Generators Get Stricter
Written by Kay Ewbank   
Friday, 30 August 2019

TypeScript has been updated with stricter generators, improvements to the UX around Promises, and an improved TypeScript playground. TypeScript is a superset of JavaScript that adds optional static types which can be checked by the TypeScript compiler to catch common errors in your programs.

Tools like the TypeScript compiler and Babel are then used to transform TypeScript to standards-compliant ECMAScript code that will work on any browser or runtime. TypeScript includes editor support for Visual Studio 2015 and 2017, Sublime Text 3 and Visual Studio Code.


The first change to the new version is the introduction of stricter checking for iterators and generator functions. Until now, if you used a generator there was no way to differentiate whether a value was yielded or returned from a generator. Changes have been made in the Interator and IteratorResult type declarations to include new type parameters, and to a new type that TypeScript uses to represent generators called the Generator type. This means you’ll be able to appropriately narrow down values from iterators when dealing with them directly.

Promise handling has also been improved, so that if they are mishandled in your code, for example by forgetting to include an await to make sure the Promise has been fulfilled before passing it to another function, you'll now get a clearer error message explaining this. 

Array spreads are another area to be improved. Until now, TypeScript has used a simplified emit by default for constructs like for/of loops and array spreads, because when they are used for pre-ES2015 targets, the standard emit is too heavy. If you wanted to iterate on other types you had to signify it using a flag and emit much larger code.  This has been causing problems, so the new release introduces a new spreadarrays helper to accurately model what happens in ES2015 when used in older targets. 

The TypeScript playground is another area to be improved with new options including:

  • The target option (allowing users to switch out of es5 to es3, es2015, esnext, etc.)
  • All the strictness flags (including just strict)
  • Support for plain JavaScript files (using allowJS and optionally checkJs)

The options also persist when sharing links to playground samples.The developers say that they'll be refreshing the playground samples in the near future, adding JSX support, and polishing automatic type acquisition, meaning that you’ll be able to see the same experience on the playground as you’d get in your personal editor.


More Information

TypeScript On NuGet

TypeScript On GitHub

Related Articles

TypeScript 3.5 Adds Smart Select 

TypeScript 3.2 Gets Stricter Checking

TypeScript 3.1 Adds Mappable Tuples

TypeScript 3.0 Adds Project References

TypeScript Adds Unused Span Reporting

TypeScript Adds Conditional Types

TypeScript 2.7 Improves Type Inference

TypeScript 2.5 Adds Optional Catch Binding

TypeScript 2.4 Adds Dynamic Import Expressions  

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.


Google Releases Vertex AI Agent Builder

Google has launched Vertex AI Agent Builder, alongside new open-source language models for the Vertex AI platform. The announcements were made at the Google Cloud Next 2024 event.

MongoDB Atlas Stream Processing Generally Available

The MongoDB developers have announced that MongoDB Atlas now has support for stream processing. The news was announced at MongoDB.Local NYC.

More News

raspberry pi books



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

Last Updated ( Saturday, 31 August 2019 )