TypeScript 2.0 Beta Supports Nullable Types

Besides support for nullable types, a beta of TypeScript 2.0 is now available that includes a smoother way of working with declaration files and makes module declarations more efficient.

A beta version of TypeScript 2.0 is now available from Microsoft, packed with a handful of features, including a smoother way of working with declaration files, support for nullable types, and simpler module declarations.

Declaration files are used to describe the shape of an external JavaScript library or host API, and a blog from Microsoft's Daniel Rosenwasser describes how the process of acquiring and declaring files is being simplified in version 2.0. Developers currently have to use package managers like tsd or Typings to use declaration files from the DefinitelyTyped declaration files repository (where library authors store .d.ts files).

"While very useful, these were extra tools to learn, and this added friction for new users," writes Rosenwasser, in a Github discussion posted here. "There were also some technical issues, such as lack of versioning and conflicting declarations, that existing tools couldn't manage." In beta 2.0, much of the process is being simplified so that developers just need to use the npm package manager to declare files.

In relation to file declaration, the TypeScript 2.0 beta has an easier way to declare modules. Modules can be declared without having to define their shapes until later. Wildcards can also be used in declarations for more efficient coding.

TypeScript 2.0 also includes two new types, null and undefined, which allows for nullable types. "They're not totally useful on their own, but you can use them in a union type to describe whether something could be null/undefined," writes Rosenwasser. It also adds a --strictNullChecks flag to check for the contents of a string.

Rosenwasser notes that handling of nullable types is a result of TypeScript 2.0's use of control flow analysis "to better understand what a type has to be at a given location," which has benefits in less debugging later on.

See Rosenwasser's blog here for some code samples, as well as links for getting the beta.

TypeScript is Microsoft's implementation of the JavaScript, a programming language for developing dynamic Web pages. TypeScript is considered a superset, adhering to JavaScript's language but allowing for extending of the JavaScript language. The latest version, 1.8, was released in February with JavaScript compilation improvements, expanded JSX support, and ChakraCore support.

About the Author

Michael Domingo is a long-time software publishing veteran, having started up and managed several developer publications for the Clipper compiler, Microsoft Access, and Visual Basic. He's also managed IT pubs for 1105 Media, including Microsoft Certified Professional Magazine and Virtualization Review before landing his current gig as Visual Studio Magazine Editor in Chief. Besides his publishing life, he's a professional photographer, whose work can be found by Googling domingophoto.

comments powered by Disqus


  • Visual Studio 2019 v16.7 Ships with Better Git Integration

    Better GitHub integration and other improvements highlight the new Visual Studio 2019 Version 16.7 and first preview of v16.8.

  • Visual Studio Codespaces Private Preview Woos C++ Developers

    Microsoft announced a private preview of Visual Studio Codespaces, which eases the setup and use of cloud-powered development environments that can be used from anywhere for remote development and other scenarios, targeting C++ console app and library developers.

  • Data Prep for Machine Learning: Normalization

    Dr. James McCaffrey of Microsoft Research uses a full code sample and screenshots to show how to programmatically normalize numeric data for use in a machine learning system such as a deep neural network classifier or clustering algorithm.

  • Microsoft Intros Azure Well-Architected Framework Best Practices

    Taking a page from the Amazon Web Services (AWS) book on cloud computing platforms, Microsoft has introduced its own Azure Well-Architected Framework, providing a set of architecture best practices to help users build and deliver great solutions and improve the quality of cloud workloads.

  • Creating a Progressive Web App with Blazor WebAssembly

    Not surprisingly, it's dead easy to create an app in Blazor that runs outside of the browser window and (potentially) in an offline mode. Before you get carried away, though, there are some key design decisions to make.

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.

Upcoming Events