What does 'Object is possibly null' mean in TypeScript?
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.

Related questions
- What does TypeError: unsupported operand type(s) mean in Python?
- How do I fix cannot convert string to int in Java?
- What does undefined is not a function mean in JavaScript?
- Why do I get a type mismatch error in C++?
- What does incompatible types: possible lossy conversion mean in Java?
- How do I fix an implicit conversion error in C#?