๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ typescript โ€บ typescript operators
TypeScript Operators
December 18, 2016 - TypeScript - null vs. undefined ... An operator defines some function that will be performed on the data. The data on which operators work are called operands.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ typescript โ€บ operator
TypeScript Operator: Syntax, Usage, and Examples
TypeScript prevents some unexpected comparisons by catching type mismatches at compile time. Perfect for conditionals and combining boolean values: ... let isActive = true; let isAdmin = false; let canEdit = isActive && isAdmin; let canView = isActive || isAdmin; You can combine logical operators with others, especially in if statements and guards.
๐ŸŒ
TypeScript
typescriptlang.org โ€บ docs โ€บ handbook โ€บ release-notes โ€บ typescript-3-7.html
TypeScript: Documentation - TypeScript 3.7
The ?? operator can replace uses of || when trying to use a default value. For example, the following code snippet tries to fetch the volume that was last saved in localStorage (if it ever was); however, it has a bug because it uses ||.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ typescript โ€บ typescript-operators
TypeScript Operators - GeeksforGeeks
August 7, 2025 - These operators provide powerful mechanisms for defining and manipulating types in a flexible and expressive manner. In TypeScript, string operators and features are used for manipulating and working with string values.
๐ŸŒ
Javatpoint
javatpoint.com โ€บ typescript-operators
TypeScript Operators - javatpoint
TypeScript Operators with typescript tutorial, typescript introduction, versions, typescript and javascript, features, components, installation, typescript first program, typescript types, etc.
๐ŸŒ
Graphite
graphite.com โ€บ guides โ€บ typescript-operators
Operators in TypeScript
The && operator (logical AND) returns true only if both operands are true; in the example, condition1 && condition2 returns false because condition2 is false. The || operator (logical OR) returns true if at least one of the operands is true, ...
๐ŸŒ
Tutlane
tutlane.com โ€บ tutorial โ€บ typescript โ€บ typescript-operators
TypeScript Operators - Tutlane
In typescript, operator is a programming element or symbol that specifies what kind of an operation can be performed on operands or variables. For example, an addition (+) operator in typescript is useful to perform sum operation on operands.
๐ŸŒ
Tektutorialshub
tektutorialshub.com โ€บ home โ€บ typescript โ€บ typescript operators
Typescript Operators - Tektutorialshub
March 15, 2023 - A Typescript operators performs some operation on one or more operands and produces a result. The operand is the data or value on which an operation is to be done. For Example, in the expression 10+2 + is an operator, while 10 & 2 are the operands.
๐ŸŒ
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 - In the example above, we have a function printUserInfo that takes a User object as an argument. We are using the ! operator on the age property to assert that it is not null or undefined.
Find elsewhere
๐ŸŒ
Scaler
scaler.com โ€บ topics โ€บ typescript โ€บ typescript-operator
TypeScript Operators - Scaler Topics
February 13, 2023 - Operators which are used with objects or assist in working with objects such as typeof, instanceof, in, or delete are generally placed in the category of Type operators. ... TypeScript operators can be generally divided into the following categories: Arithmetic, Logical, Bitwise, Relational, Assignment, Ternary, Concatenation, and Type Operators.
๐ŸŒ
W3Schools Blog
w3schools.blog โ€บ home โ€บ typescript operators list
TypeScript operators list - W3schools
February 27, 2018 - TypeScript operators list. Operator is a special symbol used for performing a specific task. e.g. A+B. Here + symbol represents the operator.
๐ŸŒ
TypeScript
typescriptlang.org โ€บ docs โ€บ handbook โ€บ 2 โ€บ typeof-types.html
TypeScript: Documentation - Typeof Type Operator
TypeScript adds a typeof operator you can use in a type context to refer to the type of a variable or property: ... This isnโ€™t very useful for basic types, but combined with other type operators, you can use typeof to conveniently express many patterns. For an example, letโ€™s start by looking at the predefined type ReturnType<T>. It takes a function type and produces its return type:
๐ŸŒ
Medium
medium.com โ€บ @shubhamshah207 โ€บ understanding-and-operators-in-typescript-4c031f49a8b4
Understanding || and ?? Operators in TypeScript | by Shubham Shah | Medium
February 10, 2025 - // Example combining both operators function processValue(input: string | null | undefined) { const value = input ?? ""; // Handle null/undefined const display = value || "Empty"; // Handle empty string return display; } console.log(processValue(null)); // "Empty" console.log(processValue("")); // "Empty" console.log(processValue("Hello")); // "Hello" The nullish coalescing operator is particularly valuable in modern TypeScript applications where you need precise control over null/undefined handling while treating other falsy values as valid data.
๐ŸŒ
Reflectoring
reflectoring.io โ€บ typescript-operators
Operators in TypeScript
July 31, 2023 - Concatenation operators in TypeScript are used to combine strings and values together. The most common concatenation operator is the plus sign (+). When used with strings, the plus sign combines them into a single string.
๐ŸŒ
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.
Top answer
1 of 7
247

! is non-null assertion operator (post-fix expression) - it just saying to type checker that you're sure that a is not null or undefined.

the operation a! produces a value of the type of a with null and undefined excluded


Optional chaining finally made it to typescript (3.7)

The optional chaining operator ?. permits reading the value of a property located deep within a chain of connected objects without having to expressly validate that each reference in the chain is valid. The ?. operator functions similarly to the . chaining operator, except that instead of causing an error if a reference is nullish (null or undefined), the expression short-circuits with a return value of undefined. When used with function calls, it returns undefined if the given function does not exist.

Syntax:

obj?.prop // Accessing object's property
obj?.[expr] // Optional chaining with expressions
arr?.[index] // Array item access with optional chaining
func?.(args) // Optional chaining with function calls

Pay attention:

Optional chaining is not valid on the left-hand side of an assignment

const object = {};
object?.property = 1; // Uncaught SyntaxError: Invalid left-hand side in assignment
2 of 7
164

Since TypeScript 3.7 was released you can use optional chaining now.

Property example:

let x = foo?.bar.baz();

This is equvalent to:

let x = (foo === null || foo === undefined)
  ? undefined
  : foo.bar.baz();

Moreover you can call:

Optional Call

function(otherFn: (par: string) => void) {
   otherFn?.("some value");
}

otherFn will be called only if otherFn won't be equal to null or undefined

Usage optional chaining in IF statement

This:

if (someObj && someObj.someProperty) {
  // ...
}

can be replaced now with this

if (someObj?.someProperty) {
  // ...
}

Ref: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html

๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ typescript โ€บ typescript logical operators examples
TypeScript Logical Operators Examples
December 18, 2016 - The && operator returns true only when both the conditions return true. Let us consider an expression โˆ’ ... In the above example, a < 10 and a > 5 are two expressions combined by an && operator. Here, the first expression returns false.
๐ŸŒ
Medium
medium.com โ€บ swlh โ€บ tech-cool-typescript-operators-you-might-not-know-312c0d0abc9c
Tech: Cool TypeScript Operators You Might Not Know | by Khoi Bui | The Startup | Medium
September 4, 2020 - One of the most annoying bugs in JS is null pointer exception, an exception occurred when the code accesses a property of a null object. To make sure developers safely check for null before accessing its property, TS introduced a brand new operator in v 3.7 called Optional Chaining.
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";
๐ŸŒ
Programiz
programiz.com โ€บ typescript โ€บ operators
TypeScript Operators
Here, we've used the * arithmetic operator to calculate the product of 2 and 4. ... Let's explore an example to see how various arithmetic operators work.