ProjectStack
typescript

TS2532: Object is possibly 'undefined'

You're accessing a property or calling a method on a value that TypeScript has determined might be undefined. Strict null checks require you to handle the undefined case before proceeding.

Common causes

  • Accessing an optional property without optional chaining: obj.optionalProp without ?.value
  • A function parameter is optional (name?: string) but you're using it as if it's always defined
  • Array or Map access without a check — myArray[0] could be undefined if the array is empty
  • A variable is declared without an initial value or initialized conditionally

How to fix it

  1. Add an undefined check: if (value !== undefined) { useValue(value) }
  2. Use optional chaining: obj.optionalProp?.nestedProp
  3. Provide a default value: const name = paramName ?? 'default'
  4. Narrow the type with a guard: if (typeof value !== 'undefined') { ... }

Example

function greet(name?: string) { return name.toUpperCase(); // error TS2532: Object is possibly 'undefined'. }

Using an optional parameter as if it's guaranteed to be defined

Browse more errors

The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.