A feature five years in the making

TypeScript 3.7 adds long-awaited optional chaining feature

Sarah Schlothauer
©Shutterstock / BrAt82

The newest version of TypeScript arrived on November 5, 2019. It includes new tooling features, optional chaining, nullish coalescing, assertion functions, and much more. TypeScript is on the up and up, according to the spring Technology Radar report, when it moseyed on up to the ‘adopt’ sector. See what’s new in the open source programming language.

TypeScript, the superset of JavaScript, offers minimal configuration management and IDE support, while still providing the benefit of JavaScript libraries. It adds optional static type-checking and type syntax and works with all browsers and operating systems.

The latest release has now been announced. Introducing TypeScript 3.7. Two of the biggest additions with this update include optional chaining and a nullish coalescing operator.

Newcomers can test out the language in the playground and see how it all works. This time around, the playground also received a few updates, including a quick fix feature, dark and high-contrast mode, and the ability to import other packages.

Optional chaining

The long wait finally ends. The issue regarding optional chaining was added five years ago, in 2014, back when TypeScript was still new. Now, one of the most requested features is officially implemented and standardized. Optional chaining reached its Stage 3 consensus.

Optional chaining allows you to write code which stops running some expressions if it hits a null or undefined.  An optional chain is an optional expression which is then followed by either regular property access, element access, or call argument lists.

SEE ALSO: Containers and security – What are the five biggest myths?

The operator uses ?..

From the proposal, it may appear in three positions:

obj?.prop       // optional static property access
obj?.[expr]     // optional dynamic property access
func?.(...args) // optional function or method call

View the pull request and proposal for more information.

Nullish Coalescing

The nullish coalescing operator works in tandem with optional chaining as a complementary operator. Nullish coalescing uses the ?? operator.

Now, the ?? operator can replace instances of || when trying to use a default value.

From the TypeScript 3.7 announcement blog:

You can think of this feature – the ?? operator – as a way to “fall back” to a default value when dealing with null or undefined. When we write code like

let x = foo ?? bar();

this is a new way to say that the value foo will be used when it’s “present”; but when it’s null or undefined, calculate bar() in its place.

Again, the above code is equivalent to the following.

let x = (foo !== null && foo !== undefined) ?

    foo :


Check out the pull request and proposal for a closer look.

3.7 updates

Nullish coalescing and optional chaining aren’t the only features arriving in this update.

Some of the other features include:

SEE ALSO: Top programming languages for November 2019: C gets an A+

  • Assertion signatures: New assertion signatures model upon JavaScript assertion functions.
  • New recursive type aliases: Restrictions on type aliases have been relaxed.
  • useDefineForClassFields flag: Declarations initialized with  Object.defineProperty; declarations now always initialized to undefined
  • Flags non-nullable function in ‘if’ statements as errors
  • Semicolon formatting: Built-in formatter support semicolon insertion and removal in instances where trailing semicolons are optional. Works with Visual Studio Code Insiders and coming soon to Visual Studio 16.4 Preview 2.
  • Improved error reporting: Error reports are now flattened and won’t extend outwards in long pyramids.

View the Microsoft dev blog for an exhaustive list of all the new features and breaking changes.

Get a head start on the next version. The TypeScript 3.8 plan is now available on GitHub. Notable expected items include top-level await.

Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is the editor for She received her Bachelor's degree from Monmouth University, West Long Branch, New Jersey. She currently lives in Frankfurt, Germany with her husband and cat where she enjoys reading, writing, and medieval reenactment. She is also the editor for Conditio Humana, an online magazine about ethics, AI, and technology.

Inline Feedbacks
View all comments