Microsoft showcases optional chaining as it lets loose TypeScript 3.7 beta

Microsoft showcases optional chaining as it lets loose TypeScript 3.7 beta

Microsoft has lifted the lid on a “feature complete” beta of TypeScript 3.7, claiming that it includes some of the most highly-requested features from end users, such as optional chaining.

TypeScript is Microsoft’s superset of JavaScript, intended to allow developers to implement larger scale applications. It is available under the Apache License 2.0, but is developed and maintained by Microsoft. The language has been gaining in popularity, even creeping into the top ten of RedMonk’s Programming Language Rankings.

The feature Microsoft is making most noise about in this release is optional chaining, which it said is one of one of the most highly demanded requests by developers.  Optional chaining essentially allows developers to write code that references object properties that may or may not exist. Instead of triggering an error, it simply returns undefined if the object does not exist.

TypeScript 3.7 employs a new ?. operator to signify such optional property accesses in code, and several can be strung together to reference nested objects – hence optional chaining.

Optional chaining in TypeScript 3.7 also includes two other operations. One is optional element access, which provides a similar function to optional property accesses but allows access to non-identifier properties such as arbitrary strings, numbers, and symbols. The second is optional call, which allows users to conditionally call expressions if they are not null or undefined.

Another feature adopted from the ECMAScript specifications is nullish coalescing. This is a rather unhelpful name for simply allowing a developer to specify a value for something if a property being referenced turns out to be null or undefined.

Other new capabilities added include Assertion Functions, better support for functions that return a value of never and more recursive type aliases. For full details, see Microsoft’s TypeScript developer blog post announcing the beta.

TypeScript 3.7 also implements a better experience for editing large projects that have been broken up into smaller chunks using project references. When opening a project with dependencies, TypeScript will automatically use the source .ts/.tsx files instead. This means projects using project references will now provide an improved experience where semantic operations are up-to-date and “just work”, according to Microsoft.

The final release of TypeScript 3.7 is due for delivery at the start of November, with a release candidate set to be available a few weeks earlier. Developers interested in evaluating the beta can get it through NuGet or download it for Visual Studio 2019/2017.