What does 'Object is possibly null' mean in TypeScript?

Updated October 2026 · How we answer

Short answerTypeScript is warning that a value might be null or undefined at that point. Narrow the type with a check, or update the declaration if null is truly impossible there.

Why the compiler raises it

With strict null checks turned on, TypeScript tracks whether a value could be null or undefined. If a function may return null, the compiler will not let you call a method on that value without a check. The message is a safety net for runtime crashes that would otherwise appear later.

The right fix depends on the situation. If null is a real possibility, add an if check before using the value. If the value is always set by that point, consider whether the type annotation is too broad and adjust the code that creates it.

Add an if check before using the value. Use optional chaining where it fits. Revisit the type if null cannot happen. Confirm the strict setting in tsconfig.

Avoiding silent shortcuts

Adding an exclamation mark to force the type tells TypeScript to trust you. That can silence the error, but if the value is actually null, the program will still fail at runtime. Use that override only when you are sure.

Read the type declaration where the value is produced. If a function returns a union with null, follow that union through the code that consumes it, and decide which branch is correct for your app.

Common mistakes

  • Using a non-null assertion on values that can truly be missing.
  • Turning off strict checks to make the message go away.
From our shopsCaseMorph: Type an idea, see a custom phone case in seconds, then print a one-of-one.