Paul Krill
Editor at Large

TypeScript 3.7 arrives with optional chaining

news
Nov 6, 20192 mins

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

futuristic flowchart 135523847
Credit: 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

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorld’s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorld’s audience of software developers and other information technology professionals. Paul has won a “Best Technology News Coverage” award from IDG.

More from this author