It's called the "Non-null assertion operator" and it tells the compiler that x.getY() is not null.

It's a new typescript 2.0 feature and you can read about it in the what's new page, here's what it says:

A new ! post-fix expression operator may be used to assert that its operand is non-null and non-undefined in contexts where the type checker is unable to conclude that fact. Specifically, the operation x! produces a value of the type of x with null and undefined excluded. 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.

// Compiled with --strictNullChecks
function validateEntity(e?: Entity) {
    // Throw exception if e is null or invalid entity
}

function processEntity(e?: Entity) {
    validateEntity(e);
    let s = e!.name;  // Assert that e is non-null and access name
}

Edit

There's an issue for documenting this feature: Document non-null assertion operator (!)

Answer from Nitzan Tomer on Stack Overflow
🌐
Learn TypeScript
learntypescript.dev › 07 › l2-non-null-assertion-operator
Using the non-null assertion operator | Learn TypeScript
The non-null assertion operator is an exclamation mark (!), and this is placed after the variable or expression that we want to tell TypeScript isn't null or undefined.
🌐
TypeScript
typescriptlang.org › docs › handbook › release-notes › typescript-2-0.html
TypeScript: Documentation - TypeScript 2.0
In regular type checking mode the ... of z is null (and therefore, absent a type annotation, null is the only possible value for z). A new ! post-fix expression operator may be used to assert that its operand is non-null and non-undefined in contexts where the type checker is ...
🌐
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 - It turned out that this operator ! placed after an expression is TypeScript’s non-null assertion operator.
Top answer
1 of 3
170

It's called the "Non-null assertion operator" and it tells the compiler that x.getY() is not null.

It's a new typescript 2.0 feature and you can read about it in the what's new page, here's what it says:

A new ! post-fix expression operator may be used to assert that its operand is non-null and non-undefined in contexts where the type checker is unable to conclude that fact. Specifically, the operation x! produces a value of the type of x with null and undefined excluded. 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.

// Compiled with --strictNullChecks
function validateEntity(e?: Entity) {
    // Throw exception if e is null or invalid entity
}

function processEntity(e?: Entity) {
    validateEntity(e);
    let s = e!.name;  // Assert that e is non-null and access name
}

Edit

There's an issue for documenting this feature: Document non-null assertion operator (!)

2 of 3
45

Non-null assertion operator: !

  • You tells the TS compiler that the value of a variable is not null | undefined
  • Use it when you are in possession of knowledge that the TS compiler lacks.

Here is a trivial example of what it does:

let nullable1: null | number;
let nullable2: undefined | string;

let foo  = nullable1! // type foo: number
let fooz = nullable2! // type fooz: string

It basically removes null | undefined from the type


When do I use this?

Typescript is already pretty good at inferring types for example using typeguards:

let nullable: null | number | undefined;

if (nullable) {
    const foo = nullable; // ts can infer that foo: number, since if statements checks this
}

However sometimes we are in a scenario which looks like the following:

type Nullable = null | number | undefined;

let nullable: Nullable;

validate(nullable);

// Here we say to ts compiler:
// I, the programmer have checked this and foo is not null or undefined
const foo = nullable!;  // foo: number

function validate(arg: Nullable) {
    // normally usually more complex validation logic
    // but now for an example
    if (!arg) {
        throw Error('validation failed')
    }
}

My personal advice is to try to avoid this operator whenever possible. Let the compiler do the job of statically checking your code. However there are scenarios especially with vendor code where using this operator is unavoidable.

🌐
GeeksforGeeks
geeksforgeeks.org › typescript › typescript-non-null-assertion-operator-postfix-type
TypeScript Non-null Assertion Operator (Postfix !) Type - GeeksforGeeks
April 28, 2025 - This operator tells TypeScript to treat the expression as if it's guaranteed to have a value, eliminating compile-time null and undefined checks. ... Type is the expected type of the value. value is the variable or expression that you're asserting ...
🌐
Biome
biomejs.dev › linter › rules › no-non-null-assertion
noNonNullAssertion | Biome
TypeScript’s ! non-null assertion operator asserts to the type system that an expression is non-nullable, as in not null or undefined. Using assertions to tell the type system new information is often a sign that code is not fully type-safe.
Find elsewhere
🌐
Kotlin
kotlinlang.org › docs › null-safety.html
Null safety | Kotlin Documentation
The not-null assertion operator !! converts any value to a non-nullable type.
🌐
TypeScript ESlint
typescript-eslint.io › rules › no-non-null-assertion
no-non-null-assertion | typescript-eslint
TypeScript's ! non-null assertion operator asserts to the type system that an expression is non-nullable, as in not null or undefined. Using assertions to tell the type system new information is often a sign that code is not fully type-safe.
🌐
Baeldung
baeldung.com › home › kotlin › kotlin basics › not-null assertion (!!) operator in kotlin
Not-Null Assertion (!!) Operator in Kotlin | Baeldung on Kotlin
March 19, 2024 - If we apply this operator on a null value, Kotlin will throw an instance of java.lang.NullPointerException: @Test fun givenNullableValue_WhenIsNull_ThenShouldThrow() { assertFailsWith<NullPointerException> { val noAnswer: String? = null noAnswer!! } } Also, if we apply !! to a non-nullable type, the compiler will still compile the code:
🌐
Better Programming
betterprogramming.pub › cleaner-typescript-with-the-non-null-assertion-operator-300789388376
Cleaner TypeScript With the Non-Null Assertion Operator | by Omri ...
February 16, 2021 - TL;DR: Adding an exclamation mark after a variable will ignore undefined or null types. The non-null assertion operator takes a typed variable and removes the undefined and null types from it.
🌐
Sentry
sentry.io › sentry answers › react › how to fix the forbidden non-null assertion in typescript and react?
How to fix the forbidden non-null assertion in TypeScript and React? | Sentry
The Non-null Assertion Operator (Postfix !) assertion removes the null and undefined types from a value. To use it, add the ! symbol after an expression like in the console log example above.
🌐
Nicotsou
nicotsou.com › tltr-typescript-non-null-assertion
Dealing With Non-Null Assertions in TypeScript
One of the most controversial features of TypeScript is definitely the Non-Null Assertion operator. It allows you to easily check for nullable values, without writing a lot of logic.
🌐
Stack Abuse
stackabuse.com › bytes › the-non-null-assertion-operator-in-typescript
The Non-Null Assertion Operator in TypeScript
August 19, 2023 - This operator, denoted by an exclamation point (!), tells TypeScript that a variable is certain to be non-null or non-undefined, even though its type might suggest otherwise. In TypeScript, the exclamation point (!) is the Non-Null Assertion Operator.
🌐
Stack Overflow
stackoverflow.com › questions › 76232881 › how-to-get-rid-of-non-null-assertion
typescript - How to get rid of non-null assertion - Stack Overflow
In TypeScript, the non-null assertion operator (!) is used to tell the compiler that a value will not be null or undefined.
🌐
TypeScript ESlint
typescript-eslint.io › rules › no-extra-non-null-assertion
no-extra-non-null-assertion | typescript-eslint
The ! non-null assertion operator in TypeScript is used to assert that a value's type does not include null or undefined.