The safe navigation operator (aka. Elvis operator) is a proposal in draft status with TC39, so no. Not yet anyway (as of this writing).

But this ugly syntax will get you there without a library. Instead of ...

foo?.bar

... use this ...

(foo||{}).bar||{}

It's hard to read but it works and it isn't dependent on a library.

UPDATE: The proposal has reached stage 4, so it will be part of ES2020.

Answer from RapPayne on Stack Overflow
🌐
DEV Community
dev.to › pssingh21 › safe-navigation-operator-bang-bang-bang-192j
Safe Navigation Operator? Bang! Bang Bang!! - DEV Community
March 12, 2021 - In this case, the compiler does not keep track that map.has() has been evaluated while evaluating map.get(). So the compiler can't determine if the map returns a safe value. This can also be used in terms of calling a possibly undefined function and array indexes. ... For example it could be used when using React refs. When using refs, the current value may be null if the element is unmounted. In JavaScript every value is assocaiated as either a truthy value or a falsy value. So, a bang(!) as a prefix on a value acts as a logical "not" operator on that value.
🌐
Medium
medium.com › @zayani.zied › safe-navigation-operator-optional-chaining-js-and-angular-d253431a2625
Safe Navigation Operator-Optional Chaining (JS and Angular) | by Zied ZAYANI | Medium
February 20, 2023 - Because it’s important to ensure that your code is concise, efficient, and easy to read. It’s recommended to use the safe navigation operator (?.) instead of relying on ngIf to check if an object is null or undefined.
🌐
Peeyush Singh's Blog
peeyushmansingh.com › safe-navigation-operator-bang-bang-bang
Safe Navigation Operator? Bang! Bang Bang!!
May 25, 2023 - In this case, the compiler does not keep track that map.has() has been evaluated while evaluating map.get(). So the compiler can't determine if the map returns a safe value. This can also be used in terms of calling a possibly undefined function and array indexes. ... For example it could be used when using React refs. When using refs, the current value may be null if the element is unmounted. In JavaScript every value is assocaiated as either a truthy value or a falsy value. So, a bang(!) as a prefix on a value acts as a logical "not" operator on that value.
🌐
npm
npmjs.com › package › safe-navigator
safe-navigator - npm
If you want to access obj.key1.key2.key3, you can import the package as safe and try safe(obj, "key1.key2.key3") and even if key1 does not contain a key called key2 and you try to access key3 in an undefined value of key2, the function will return the value of undefined without throwing an error. If you pass a third argument to safe(obj, "key1.key2.key3", []), incase the value is undefined, the fallback will be returned by safe.
      » npm install safe-navigator
    
Published   May 08, 2021
Version   1.1.7
Author   Anand Jain
🌐
React Navigation
reactnavigation.org › docs › handling-safe-area
Supporting safe areas | React Navigation
The area not overlapped by such items is referred to as "safe area". We try to apply proper insets on the UI elements of the navigators to avoid being overlapped by such items. The goal is to (a) maximize usage of the screen (b) without hiding content or making it difficult to interact with by having it obscured by a physical display cutout or some operating system UI. While React Navigation handles safe areas for the built-in UI elements by default, your own content may also need to handle it to ensure that content isn't hidden by these items.
🌐
NGCC in Angular Ivy
iq.js.org › questions › angular › what-is-safe-navigation-operator
What is safe navigation operator?
November 11, 2025 - The safe navigation operator(?)(or known as Elvis Operator) is used to guard against null and undefined values in property paths when you are not aware whether a path exists or not.
🌐
Stackademic
blog.stackademic.com › achieving-type-safety-with-usenavigation-in-react-navigation-cb96ccc5b9e3
Achieving Type-Safety with useNavigation in React Navigation | by Vaibhav Naik | Stackademic
October 5, 2023 - // types/navigation.ts import { FC } from 'react'; import { NativeStackScreenProps } from '@react-navigation/native-stack'; export type RouteParams = { LANDING: undefined; HOME: undefined; SEARCH: { searchQuery?: string; }; // ... other route params }; /** * A type helper for defining React components associated with specific routes. * * Usage: * const MyComponent: RouteComponent = ({ navigation }) => {...} */ export type RouteComponent = FC<NativeStackScreenProps<RouteParams>>; Finally, create a custom hook, useTypeSafeNavigation, to wrap around the useNavigation hook. This will ensure type-safety every time you need to navigate.
🌐
Reddit
reddit.com › r/typescript › is there a safe navigation operator for string indexes?
r/typescript on Reddit: Is there a safe navigation operator for string indexes?
November 2, 2022 -

If I try to look up a string index on a nullable object like obj['index'] I get an Object is possibly 'null' error. I know I can do obj && obj['index'] but this gets tiresome especially if you are following multiple levels deep.

obj?['index'] thinks I am trying to do a ternary operator. Is there some sort of way to sugar syntax this?

Find elsewhere
🌐
Medium
medium.com › @didemsahin1789 › protected-routes-and-navigation-guards-in-react-native-21f91592433e
Protected Routes and Navigation Guards in React Native | by Didem Şahin | Medium
September 17, 2025 - // src/hooks/useRouteGuard.ts import { useEffect } from 'react'; import { useRouter } from 'expo-router'; import { useAuth } from '../context/AuthContext'; export const useRouteGuard = ({ requireAuth = true, requiredRole, redirectTo = '/auth/login', }: { requireAuth?: boolean; requiredRole?: 'admin' | 'user'; redirectTo?: string; } = {}) => { const { isAuthenticated, user, loading } = useAuth(); const router = useRouter(); useEffect(() => { if (loading) return; if (requireAuth && !isAuthenticated) { router.replace(redirectTo); return; } if (requiredRole && user?.role !== requiredRole) { router.replace('/access-denied'); return; } }, [isAuthenticated, user, loading]); return { isAuthorized: isAuthenticated && (!requiredRole || user?.role === requiredRole), isLoading: loading, }; };
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

🌐
GitHub
github.com › microsoft › TypeScript › issues › 16
Suggestion: "safe navigation operator", i.e. x?.y · Issue #16 · microsoft/TypeScript
July 15, 2014 - Current Status The TC39 proposal is now at stage 3 (🎉🎉🎉🎉🎉) Implementation is in progress You can expect this feature in TypeScript 3.7 We'll update here when it's available in a nightly bui...
Published   Jul 15, 2014
🌐
Designcise
designcise.com › web › tutorial › does-javascript-have-safe-navigation-operator
Does JavaScript Have Safe Navigation Operator? - Designcise
August 22, 2021 - The safe navigation operator is simply another name for the optional chaining operator (?.), which was introduced in ES11. It evaluates an expression from left-to-right; when/if the left operand evaluates to a nullish value, it stops the execution ...
🌐
Wikipedia
en.wikipedia.org › wiki › Safe_navigation_operator
Safe navigation operator - Wikipedia
1 month ago - The main advantage of using this operator is that it avoids the pyramid of doom. Instead of writing multiple nested ifs, programmers can just use usual chaining, but add question mark symbols before dots (or other characters used for chaining). While the safe navigation operator and null coalescing operator are both null-aware operators, they are operationally different.
🌐
Medium
medium.com › @garfunkel61 › unwrapping-angulars-safe-navigation-operator-7641434aa29d
Unwrapping Angular’s Safe Navigation Operator | by Andy Dłubak | Medium
August 22, 2023 - Wouldn’t it be reassuring to know there’s water inside? In Angular, the safe navigation operator (aka the “Elvis operator”) acts as a reassurance. It’s a way of checking if there’s “water in the pool” before taking the leap.
🌐
React Navigation
reactnavigation.org › docs › typescript
Type checking with TypeScript | React Navigation
The RootParamList interface lets React Navigation know about the params accepted by your root navigator. Here we extend the type RootStackParamList because that's the type of params for our stack navigator at the root. The name of this type isn't important. Specifying this type is important if you heavily use useNavigation, Link etc. in your app since it'll ensure type-safety.
🌐
AppHelion
apphelion.dev › using safeareaview with react native navigation
Using SafeAreaView with React Native Navigation
// HomeScreen.tsx import React from 'react'; import {Button, Text, View} from 'react-native'; import {SafeAreaView} from 'react-native-safe-area-context'; import {HomeScreenNavigationProp} from '../types'; type Props = { navigation: HomeScreenNavigationProp; }; function HomeScreen({navigation}: Props): React.JSX.Element { return ( <SafeAreaView style={{flex: 1}}> <View style={{padding: 5, alignItems: 'center', justifyContent: 'center', flex: 1}}> <Text>HomePage</Text> <Button title="Go to the profile screen" onPress={() => navigation.navigate('Profile', {name: 'Jane'})} /> </View> </SafeAreaView> ); } export default HomeScreen;
🌐
CodeGuru
codeguru.co.in › home › angular › what is safe navigation operator in angular?
What is safe navigation operator in Angular?
June 7, 2021 - The Safe Navigation Operator is also known as the “Elvis Operator”. This operator is very useful to protect against null and undefined values in property paths.