TypeScript 3.7 arrives with optional chaining

Latest TypeScript includes a highly requested ECMAScript feature for dealing with null and undefined values

TypeScript 3.7 arrives with optional chaining
Thinkstock

TypeScript 3.7, the latest version of Microsoft’s typed superset of JavaScript, is now generally available. The new production release features optional chaining, an ECMAScript feature that allows developers to stop running expressions if they encounter a null or undefined value. 

Optional chaining uses a new ?. operator for optional property accesses. Also included are two other operations: optional element access, for accessing non-identifier properties such as numbers and arbitrary strings, and optional call, for conditionally calling expressions if they are not null or undefined.

[ Also on InfoWorld: Visual Studio Code vs. Sublime Text: How to choose |  Keep up with hot topics in software development with InfoWorld’s App Dev Report newsletter ]

Other highlights of TypeScript 3.7 include:

  • A nullish coalescing operator, an upcoming ECMAScript feature that is paired with operational chaining, that provides a way to fall back to a default value when working with null or undefined, via a ?? operator.
  • Improved support for never-returning functions. The intent of the never function is that it never returns, indicating an exception was thrown, a halting error condition occurred, or a program exited.
  • Assertion signatures, which model assertion functions. The first assertion signature models the Node assert function, ensuring that whatever condition is being checked must be true for the remainder of the container scope. Also, asserts condition stipulates that whatever is passed into the condition parameter has to be true if the assert returns. Another type of assertion signature does not check for a condition but tells TypeScript that a specific variable or property has a different type.
  • The ability to add // @ts-nocheck comments at the top of TypeScript files to disable semantic checks.
  • When opening a project with dependencies, TypeScript will use source .ts/.tsx files instead of project references, to provide a better editing experience.
  • The built-in formatter now supports semicolon insertion and removal where a trailing semicolon is optional because of JavaScript’s automatic semicolon insertion rules.
  • More recursive type aliases.
  • The --declaration flag, for generating .d.t.s (declaration) files from source TypeScript files, now can work with the ---allowjs setting to mix TypeScript and JavaScript input files.
  • Types in lib.dom.d.ts have been updated. These are largely correctness changes.

Where to download TypeScript 3.7

You can download TypeScript 3.7 through NuGet or via NPM:

    npm install typescript

Copyright © 2019 IDG Communications, Inc.