Error AtlasError Documentation and Resolution

TypeScript warns that the object is possibly null

error TS2531: Object is possibly 'null'.

TypeScript found code that uses a value as a non-null object even though strict null checking still allows that value to be null.

error TS2531: Object is possibly 'null'.
  • A value can be null under strict null checks.
  • Control flow has not narrowed the value before use.
  • A DOM query, lookup, or API result can return null and is being used directly.
  1. Add a null check before reading properties or calling methods on the value.
  2. Use control-flow narrowing so TypeScript can prove the value is non-null.
  3. Only use non-null assertions when you are certain the value cannot actually be null at runtime.
TypeScript TSConfig: strictNullChecks
TS2531 Object is possibly null: causes and fixes | Error Atlas