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


  • AI for GitHub Collaboration? Maybe Not So Much

    No doubt GitHub Copilot has been a boon for developers, but AI might not be the best tool for collaboration, according to developers weighing in on a recent social media post from the GitHub team.

  • Visual Studio 2022 Getting VS Code 'Command Palette' Equivalent

    As any Visual Studio Code user knows, the editor's command palette is a powerful tool for getting things done quickly, without having to navigate through menus and dialogs. Now, we learn how an equivalent is coming for Microsoft's flagship Visual Studio IDE, invoked by the same familiar Ctrl+Shift+P keyboard shortcut.

  • .NET 9 Preview 3: 'I've Been Waiting 9 Years for This API!'

    Microsoft's third preview of .NET 9 sees a lot of minor tweaks and fixes with no earth-shaking new functionality, but little things can be important to individual developers.

  • Data Anomaly Detection Using a Neural Autoencoder with C#

    Dr. James McCaffrey of Microsoft Research tackles the process of examining a set of source data to find data items that are different in some way from the majority of the source items.

  • What's New for Python, Java in Visual Studio Code

    Microsoft announced March 2024 updates to its Python and Java extensions for Visual Studio Code, the open source-based, cross-platform code editor that has repeatedly been named the No. 1 tool in major development surveys.

Subscribe on YouTube