property of a type system that prevents certain erroneous or undesirable program behaviours
In computer science, type safety is the extent to which a programming language discourages or prevents type errors. Type-safe languages are sometimes also called strongly or strictly typed. The behaviors classified as … Wikipedia
🌐
Wikipedia
en.wikipedia.org › wiki › Type_safety
Type safety - Wikipedia
2 weeks ago - Each function that exchanges objects derived from a specific class, or implementing a specific interface, will adhere to that contract: hence in that function the operations permitted on that object will be only those defined by the methods of the class the object implements.
🌐
Marius Schulz
mariusschulz.com › blog › nullish-coalescing-the-operator-in-typescript
Nullish Coalescing: The ?? Operator in TypeScript — Marius Schulz
August 14, 2021 - A deep dive into the fundamnetals of TypeScript’s type system. Learn about the optional chaining ( ?.) and nullish coalescing (??) operators, assertion functions, truly private class fields, conditional types, template literal types, adn more.
Discussions

Typescript & operator - Stack Overflow
I'm struggling to find the definition of the & operator in TypeScript. I have recently come across the following code: type IRecord = T & TypedMap ; What does that operato... More on stackoverflow.com
🌐 stackoverflow.com
Does Typescript support the ?. operator? (And, what's it called?) - Stack Overflow
Does Typescript currently (or are there plans to) support the safe navigation operator of ?. ie: var thing = foo?.bar // same as: var thing = (foo) ? foo.bar : null; Also, is there a more common ... More on stackoverflow.com
🌐 stackoverflow.com
In TypeScript, what is the ! (exclamation mark / bang) operator when dereferencing a member? - Stack Overflow
My understanding is the ! operator do the same thing like NonNullable. let ns: string | null = '' // ^? let ns: string | null let s1 = ns! // ^? let s1: string let s2 = ns as NonNullable // ^? let s2: string ... Non-Nullable TypeScript performs strict null checks to help catch potential ... More on stackoverflow.com
🌐 stackoverflow.com
Spread operator
Afraid not. Javascript get syntax does not create a property that is enumerable. It can be accessed directly but won't be accessed via an object spread or a for/in loop. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#using_getters_in_classes More on reddit.com
🌐 r/typescript
22
4
August 8, 2024
🌐
Mimo
mimo.org › glossary › typescript › operator
TypeScript Operator: Syntax, Usage, and Examples
You use operators throughout your code to assign values, compare data, manipulate collections, or perform logic checks. TypeScript supports arithmetic, assignment, comparison, logical, bitwise, ternary, nullish coalescing, and spread operators.
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-3-7.html
TypeScript: Documentation - TypeScript 3.7
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.
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";
Find elsewhere
🌐
Graphite
graphite.com › guides › typescript-operators
Operators in TypeScript
This guide will cover the fundamental and advanced operators in TypeScript, providing a clear understanding of their syntax and practical usage. We'll explore various operators such as the ternary operator, spread operator, and more.
🌐
CodeSignal
codesignal.com › learn › courses › typescript-foundations-for-beginners › lessons › typescript-comparison-mastery-understanding-operators-and-decision-making
TypeScript Comparison Mastery: Understanding Operators ...
Life and programming both involve a lot of comparisons, and TypeScript is no exception. TypeScript comparison operators, which are similar to JavaScript's, include ==, !=, ===, !==, >, <, >=, <=. Let's dive straight into an example:
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › basic-types.html
TypeScript: Documentation - The Basics
While sometimes that implies a trade-off in what you can express, the intent is to catch legitimate bugs in our programs. And TypeScript catches a lot of legitimate bugs. ... random < 0.5;Operator '<' cannot be applied to types '() => number' and 'number'.2365Operator '<' cannot be applied to types '() => number' and 'number'.
🌐
TypeScript
typescriptlang.org › docs › handbook › advanced-types.html
TypeScript: Documentation - Advanced Types
Luckily, you don’t need to abstract typeof x === "number" into its own function because TypeScript will recognize it as a type guard on its own. That means we could just write these checks inline. ... These typeof type guards are recognized in two different forms: typeof v === "typename" and typeof v !== "typename", where "typename" can be one of typeof operator’s return values ("undefined", "number", "string", "boolean", "bigint", "symbol", "object", or "function").
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › typescript-operators
TypeScript Operators - GeeksforGeeks
August 7, 2025 - TypeScript operators are symbols or keywords that perform operations on one or more operands.
🌐
Medium
medium.com › @tar.viturawong › a-note-on-typescript-non-null-assertion-operator-bad8fbe62bba
A note on TypeScript non-null assertion operator | by Tar Viturawong | Medium
March 25, 2019 - The fine print of this operator is that it is completely your responsibility to take the risk of ignoring the nullness of your expression. In fact, TypeScript’s release note implicitly hints at a good practice:
🌐
Medium
medium.com › @shubhamshah207 › understanding-and-operators-in-typescript-4c031f49a8b4
Understanding || and ?? Operators in TypeScript | by Shubham Shah | Medium
February 10, 2025 - TypeScript provides two important operators for handling default values and conditional logic: the logical OR operator (||) and the nullish coalescing operator (??).
🌐
DEV Community
dev.to › tmaximini › typescript-bang-operator-considered-harmful-3hhi
Typescript: Bang operator considered harmful - DEV Community
December 3, 2020 - Similar to type assertions of the forms x and x as T, the ! non-null assertion operator is simply removed in the emitted JavaScript code. Sounds difficult. But all it does is basically telling the compiler "this value can not be null or undefined". One of the great advantages of Typescript is that it checks your code instantly for any type errors (duh), so whenever you are working with an object or variable value that might be undefined, it gives you a warning.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators
Expressions and operators - JavaScript | MDN
Member operators provide access to a property or method of an object (object.property and object["property"]).
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Spread_syntax
Spread syntax (...) - JavaScript | MDN
You can make an element present or absent in an object literal, depending on a condition, using a conditional operator.
🌐
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 - The ! operator is a non-null assertion operator that tells the compiler that a variable or property is not null or undefined, and it should be treated as such. In this article, we will discuss how to use the !
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Nullish_coalescing
Nullish coalescing operator (??) - JavaScript | MDN
The nullish coalescing (??) operator is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.
🌐
TypeScript
typescriptlang.org › docs › handbook › 2 › everyday-types.html
TypeScript: Documentation - Everyday Types
JavaScript has three very commonly used primitives: string, number, and boolean. Each has a corresponding type in TypeScript. As you might expect, these are the same names you’d see if you used the JavaScript typeof operator on a value of those types: