Yes. As of TypeScript 3.7 (released on November 5, 2019), this feature is supported and is called Optional Chaining:

At its core, optional chaining lets us write code where TypeScript can immediately stop running some expressions if we run into a null or undefined. The star of the show in optional chaining is the new ?. operator for optional property accesses.

Refer to the TypeScript 3.7 release notes for more details.


Prior to version 3.7, this was not supported in TypeScript, although it was requested as early as Issue #16 on the TypeScript repo (dating back to 2014).

As far as what to call this operator, there doesn't appear to be a consensus. In addition to "optional chaining" (which is also what it's called in JavaScript and Swift), there are a couple of other examples:

  • CoffeeScript refers to it as the existential operator (specifically, the "accessor variant" of the existential operator):

The accessor variant of the existential operator ?. can be used to soak up null references in a chain of properties. Use it instead of the dot accessor . in cases where the base value may be null or undefined.

  • C# calls this a null-conditional operator.

a null-conditional operator applies a member access, ?., or element access, ?[], operation to its operand only if that operand evaluates to non-null; otherwise, it returns null.

  • Kotlin refers to it as the safe call operator.

There are probably lots of other examples, too.

Answer from Donut on Stack Overflow
Top answer
1 of 15
432

Yes. As of TypeScript 3.7 (released on November 5, 2019), this feature is supported and is called Optional Chaining:

At its core, optional chaining lets us write code where TypeScript can immediately stop running some expressions if we run into a null or undefined. The star of the show in optional chaining is the new ?. operator for optional property accesses.

Refer to the TypeScript 3.7 release notes for more details.


Prior to version 3.7, this was not supported in TypeScript, although it was requested as early as Issue #16 on the TypeScript repo (dating back to 2014).

As far as what to call this operator, there doesn't appear to be a consensus. In addition to "optional chaining" (which is also what it's called in JavaScript and Swift), there are a couple of other examples:

  • CoffeeScript refers to it as the existential operator (specifically, the "accessor variant" of the existential operator):

The accessor variant of the existential operator ?. can be used to soak up null references in a chain of properties. Use it instead of the dot accessor . in cases where the base value may be null or undefined.

  • C# calls this a null-conditional operator.

a null-conditional operator applies a member access, ?., or element access, ?[], operation to its operand only if that operand evaluates to non-null; otherwise, it returns null.

  • Kotlin refers to it as the safe call operator.

There are probably lots of other examples, too.

2 of 15
157

It is now possible, see answer of user "Donut".

Old answer: Standard JavaScript behaviour regarding boolean operators has something that may help. The boolean methods do not return true or false when comparing objects, but in case of OR the first value that is equal to true.

Not as nice as a single ?, but it works:

var thing = foo && foo.bar || null;

You can use as many && as you like:

var thing = foo && foo.bar && foo.bar.check && foo.bar.check.x || null;

Default values are also possible:

var name = person && person.name || "Unknown user";
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-3-7.html
TypeScript: Documentation - TypeScript 3.7
You can think of this feature - the ?? operator - as a way to “fall back” to a default value when dealing with null or undefined.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Nullish_coalescing
Nullish coalescing operator (??) - JavaScript | MDN
The nullish coalescing operator treats undefined and null as specific values. So does the optional chaining operator (?.), which is useful to access a property of an object which may be null or undefined.
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-2-0.html
TypeScript: Documentation - TypeScript 2.0
The && operator adds null and/or undefined to the type of the right operand depending on which are present in the type of the left operand, and the || operator removes both null and undefined from the type of the left operand in the resulting union type.
🌐
W3Schools
w3schools.com › typescript › typescript_null.php
TypeScript Null & Undefined
Optional chaining is a JavaScript feature that works well with TypeScript's null handling. It allows accessing properties on an object that may or may not exist, using compact syntax. It can be used with the ?. operator when accessing properties.
🌐
Learn TypeScript
learntypescript.dev › 07 › l2-non-null-assertion-operator
Using the non-null assertion operator | Learn TypeScript
We can, of course, use a type assertion to resolve the type error. However, the non-null assertion operator is a more concise solution to type errors that involve null or undefined. It is worth noting that if the code were more straightforward, then TypeScript would understand that text on the return statement wasn't null.
🌐
TypeScript
typescriptlang.org › play › 3-7 › syntax-and-messaging › nullish-coalescing.ts.html
TypeScript: Playground Example - Nullish Coalescing
The nullish coalescing operator is an alternative to || which returns the right-side expression if the left-side is null or undefined. In contrast, || uses falsy checks, meaning an empty string or the number 0 would be considered false.
🌐
Marius Schulz
mariusschulz.com › blog › nullish-coalescing-the-operator-in-typescript
Nullish Coalescing: The ?? Operator in TypeScript — Marius Schulz
August 14, 2021 - TypeScript 3.7 added support for the ?? operator, which is known as the nullish coalescing operator. We can use this operator to provide a fallback value for a value that might be null or undefined.
Find elsewhere
🌐
LogRocket
blog.logrocket.com › home › optional chaining and nullish coalescing in typescript
Optional chaining and nullish coalescing in TypeScript - LogRocket Blog
June 4, 2024 - Hence, since version 3.7, TypeScript has introduced optional chaining and nullish coalescing. As we saw in the introduction, the core of optional chaining is the ?. operator, allowing us to stop running expressions when the runtime encounters a null or undefined.
🌐
Honlsoft
honlsoft.com › blog › 2021-07-20-typescript-tips-null-coalescing
Typescript Tips: null(and undefined) Checking | Honlsoft
Thankfully, in Typescript, there are several shorthand ways to deal with nulls. The Elvis operator is a shorthand way to check for null or undefined without requiring a separate if statement.
🌐
Reddit
reddit.com › r/typescript › nullish coalescing operator vs logical or
r/typescript on Reddit: Nullish Coalescing Operator vs Logical OR
July 13, 2022 -

Take this interface for example

interface Item {
  value?: number
}

Which among the two do you prefer if you will be accessing the value property of an item and why?

console.log(item.value ?? 1.00) // 1.00 is the fallback value
console.log(item.value || 1.00) // 1.00 is the fallback value

Personally, I prefer to use the nullish coalescing operator ?? for fallback values since it's more explicit and it sames me from the weird falsy values that JavaScript has.

🌐
GitHub
github.com › microsoft › TypeScript › issues › 26578
Nullish coalescing operator (??) · Issue #26578 · microsoft/TypeScript
June 27, 2018 - In conjunction with the safe chaining operator (#16), handling optionals would be trivial. export interface Configuration { // Default: "(no name)"; empty string IS valid name?: string; // Default: -1; 0 is valid items?: number; // Default: true active?: boolean; } function configureSomething(config: Configuration) { // With null-coalescing operator config.name = config.name ??
Published   Aug 21, 2018
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › nullish-coalescing-operator-in-typescript
Nullish Coalescing Operator (??) in TypeScript - GeeksforGeeks
July 23, 2025 - The nullish coalescing (??) operator is a logical operator in TypeScript that returns its right-hand side operand if the left-hand side operand is null or undefined; otherwise, it returns the left-hand side operand.
🌐
Medium
medium.com › @bobjunior542 › how-to-use-the-operator-in-typescript-for-cleaner-more-efficient-code-7fd528f8f8b1
How to Use the ‘!’ Operator in TypeScript for Cleaner, More Efficient Code | by Bob Junior | Medium
April 25, 2023 - If the age property is null or undefined, we are using a type guard to narrow down the type of the user object. ... The ! operator is a powerful tool in TypeScript that can help you avoid compilation errors when working with nullable types.
🌐
GitHub
github.com › Microsoft › TypeScript › issues › 8690
Suggestion: Null-conditional operator · Issue #8690 · microsoft/TypeScript
February 5, 2016 - var n1 = 5; var n2 = undefined; var b = false; console.log(n1 == null ? n1 : n1.toString() || ''); // '5' console.log(n2 == null ? n2 : n2.toString() || ''); // '' console.log(b == null ?
Published   May 19, 2016
🌐
Omarileon
omarileon.me › blog › typescript-non-null-assertion
mari. | Typescript Non-Null Assertions: That Weird Exclamation Mark Operator
February 2, 2024 - The non-null assertion operator, or that weird exclamation mark you might be seeing in TypeScript is an operator that tells TypeScript that a value won't be null or undefined. In a technical sense, it eliminates null and undefined from the type ...
🌐
DEV Community
dev.to › audreyk › when-to-use-the-non-null-assertion-operator-in-typescript-545f
🧭 🇹 When to use the non-null assertion operator in TypeScript - DEV Community
August 18, 2024 - The non-null assertion operator (!) is used to assert that a value is neither null nor undefined. It tells TypeScript's type checker to ignore the possibility that the value is null or undefined, thus bypassing type checking for these values.
🌐
egghead.io
egghead.io › lessons › typescript-use-the-nullish-coalescing-operator-in-typescript
Use the Nullish Coalescing Operator in TypeScript | egghead.io
This lesson introduces the ?? operator which is known as nullish coalescing. The ?? operator produces the value on the right-hand side if (and only if) ...
Published   February 17, 2021