TypeScript 2.0 Adds Null, Undefined And Never
TypeScript 2.0 Adds Null, Undefined And Never
Friday, 23 September 2016

TypeScript 2.0 has been released with support for new data types including Null and Undefined. 

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It was developed by Microsoft for creating complex applications, and is a built-in programming language for Visual Studio. 

TypeScript 2.0 adds several new features  to help developers work more effectively, is more aligned with ECMAScript’s evolution, and has better support for JavaScript libraries and tools.

One change to the new version is support for two special types, Null and Undefined, that (strangely enough) have the values null and undefined respectively. Until now you couldn't explicitly name these types, as the type checker considered null and undefined assignable to anything. Because null and undefined were essentially valid values of every type, you couldn't specifically exclude them or detect erroneous use of them.

A new strict null checking mode, removes the null and undefined values from the domain of every type, and only allows them to be assigned to themselves and any. 

The support for types has also been increased with the implementation of a control flow-based type analysis for local variables and parameters. In earlier versions type analysis was limited to If statements. In the new version the type checker analyses all possible flows of control in statements and expressions to produce the most specific type possible (the narrowed type) at any given location for a local variable or parameter that is declared to have a union type.

A new primitive type has also been added in this version, the never type. As the release notes say:

"This represents the type of values that never occur. Specifically, never is the return type for functions that never return and never is the type of variables under type guards that are never true."

Because never is a subtype of every type, it is always omitted from union types and it is ignored in function return type inference as long as there are other types being returned.

On a more positive note, Glob support has been added to tsconfig.json. This has been one of the most requested features, according to the developers, partially because of the number of third party tools have now support tsconfig.json, most of which support some sort of extension to tsconfig.json that supports file globs.The addition within TypeScript itself regularises the situation.

typescriptlogo 

 

More Information

TypeScript Blog

Related Articles

Visual Studio "VS 15" Preview Released

TypeScript 1.8 Hits Beta

TypeScript 1.7 Released

Visual Studio Tools Updated

TypeScript 1.5 Released       

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

 

Banner


Microsoft Kills The Kinect
29/10/2017

This is a very strange "end of era" story. The Microsoft Kinect 3D sensor is dead and gone. How can such a ground breaking device be removed? Before you ask, there doesn't seem to be an alternative.&n [ ... ]



MS Open Sources Java Debugger For VS Code
02/11/2017

Microsoft has open sourced the Java debugger from the Visual Studio Code editor, along with the Java Debug Server that it uses on the back end. 


More News

 

 
 

 

blog comments powered by Disqus

Last Updated ( Friday, 23 September 2016 )
 
 

   
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.