๐ŸŒ
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.
๐ŸŒ
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.
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
Does anyone miss operator overloading?
I like that in Haskell you can turn any regular function into an infix operator by surrounding it with backticks. So your example would be something like skullcup = cup `union` (skull `sub` convex_hull(cup `sub` handle `sub` lip)) Of course backticks are taken in JS but I'm sure we could find another chunk in the ASCII soup bowl to use! More on reddit.com
๐ŸŒ r/typescript
104
71
January 27, 2024
Do you default to === or == (strict equality operator vs equality operator)
I haven't seen anyone advocate for == anywhere... ever. Pretty much as soon as === was added to JS I think everyone thought it was a good idea. As a bonus it is faster too. More on reddit.com
๐ŸŒ r/typescript
101
15
February 28, 2024
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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 โ€บ 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").
Find elsewhere
๐ŸŒ
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 (??).
๐ŸŒ
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:
๐ŸŒ
Programiz
programiz.com โ€บ typescript โ€บ operators
TypeScript Operators
In TypeScript, an operator is a special symbol that checks, changes, or combines operands (values). In this tutorial, you will learn about TypeScript operators with the help of examples.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ UploadFile โ€บ 5089e0 โ€บ logical-operators-in-typescript
Logical Operators in TypeScript
May 18, 2020 - Logical Operators work with Boolean values. In a logical operator, if you use the AND operator, the compound expression returns true if both expressions are true. If you use the OR operator then the compound expression returns true if either is true.
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";
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Operators โ€บ Nullish_coalescing
Nullish coalescing operator (??) - JavaScript | MDN
The nullish coalescing operator has the fifth-lowest operator precedence, directly lower than || and directly higher than the conditional (ternary) operator.
๐ŸŒ
Tutlane
tutlane.com โ€บ tutorial โ€บ typescript โ€บ typescript-operators
TypeScript Operators - Tutlane
Operators in typescript with examples. In typescript operators are useful to perform operations like relational, logical, etc.
๐ŸŒ
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:
๐ŸŒ
Reddit
reddit.com โ€บ r/typescript โ€บ does anyone miss operator overloading?
r/typescript on Reddit: Does anyone miss operator overloading?
January 27, 2024 -

Operator overloading is a programming language feature which allows you to define how operators such as + - * / work on particular types. It's usually considered an object orientated feature - when you define your class, you can define how instances behave when added with the '+' operator, etc. This allows math with types other than integer and floating point numbers to be written more naturally - vector and matrix arthmetic, or complex numbers, for example. It also allows languages which lack a native string type to implement string concatanation (for example the std::string in C++ implments a '+' operator for string concatanation).

The reason many languages, including TypeScript and JavaScript, purposely omit operator overloading is that it can make code harder to read - operators are easy to gloss over and may have unexpected effects. Most of the time it's better to be sure that 'math is math'.

I've been TypeScript full stack for the last three years, and gradually moving away from C++ before that, and have never really missed operator overloading.

However, I've been playing with 3D meshes in the last few weeks, defined in stl files, possibly with a view to designing something for printing in 3D. I want to combine an object which is functional - a cup - with one that is decorative - a skull, to create a skull cup that is both functional and decorative, and maybe something of a momento mori. (a skull is functional of course - keeps my brain safe in my head - but I don't see any functional value of printing one out in plastic). I have a formula for doing this while maintaining the functional aspects of the cup:

skullcup = skull - convex_hull(cup - handle - lip) + cup

The problem is the variables are 3D meshes not numbers and the operators are boolean union and difference functions that operate upon these meshes. I know how to write that in TypeScript, it's just horrible to read and emotionally speaking just isn't the same!

So it got me thinking - is there some npm package or way of subverting the language that will give me something more like operator overloading?

So that's my question. Does anyone miss operator overloading, and do you have a subitute for it, please?

To do this and keep the type-safety of TypeScript, one would perhaps have to define a language extension, like how tsx is an extension of TypeScript which allows React code to be nicely written nicely in a way that retains type checking, but that seems like overkill!


Now I've got a confession to make, I've been doing this in Python with a libary called PyMesh. I'm finding I love PyMesh except I can't quite get the last piece of the formula to work, which ever way I put it together it always seems to fall over at the final hurdle... but I hate Python!

Just to be clear, that's a matter of experience and person taste. Naturally here we think TypeScript is better and have our reasons, but anyone familiar with Python finding themselves stuck with TypeScript - the reverse of my present situation - totally has my sympathy!

So, just as an aside, if you know of any npm packages that can do unions, difference, and convex_hulls on meshes loaded from stl files, I'll bite your hand off for it! Please :-)

I'm aware ThreeJS can import from stl, but I don't think it can do these specific operations and save it back out. Or maybe I've just been using it wrong.

Python does have operator overloading, so that's a minor blessing, and probably what got me thinking about it. However, the formula shared above written out without operator overloading looks like this. I'm sharing this piece of syntax because it happens to be identical with TypeScript's syntax. Note I've rearranged a few commutative operations in a vain attempt to get my code to work:

skullcup = pymesh.boolean(
    cup,
    pymesh.boolean(
        skull,
        pymesh.convex_hull(
            pymesh.boolean(
                cup,
                pymesh.boolean(
                    handle,
                    lip,
                    'union',
                    'cork'),
                'difference',
                'cork')
        ),
        'difference',
        'cork'),
    'union',
    'cork')

So, I think you'll agree, in this particular case at least, the code is much nicer with operator overloading.