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


  • C# Slides in Usage Ranking of Programming Languages

    "The fact that C# lost three places in the ranking of language communities during the last three years is mostly explained by its slower growth compared to C/C++ and PHP."

  • Telerik UI for Blazor Updated

    Progress announced an update to its Telerik UI for Blazor components, targeting Microsoft's open source Blazor framework that lets C# coders create web apps without having to rely upon JavaScript.

  • Infragistics Unveils UI Components for Blazor

    Infragistics, specializing in third-party UI/UX controls and tools, unveiled a new offering targeting Blazor, Microsoft's red-hot open source framework that allows for C#-based web development instead of traditional mainstay JavaScript.

  • AWS Open Sources Tool for Porting .NET Framework Apps to .NET Core

    Leading cloud computing platform Amazon Web Services open sourced the it announced in July for helping users port old .NET Framework applications to the new .NET Core framework.

  • Uno Platform Ports Windows Calculator to Linux

    Uno Platform has ported the famed Windows Calculator, open sourced last year, to Linux as part of a continuing "proof point" effort to demonstrate the reach of what it describes as the sole UI offering available to target Windows, WebAssembly, iOS, macOS, Android and Linux with single-codebase applications coded in C# and XAML.

Upcoming Events