Special Sponsor:PromptBuilder— Fast, consistent prompt creation powered by 1,000+ expert templates.
Make your Product visible here.Contact Us

Home/TypeScript Errors/TS2532

TS2532

Object is possibly 'undefined'

TypeScript TS2532 fires when you access a property or call a method on a value that could be undefined. It's the undefined equivalent of TS2531 and requires you to guard against undefined before use.

Why This Happens

The value's type includes undefined — from optional function parameters, optional object properties (?:), Array.find(), Map.get(), and similar APIs that return T | undefined. TypeScript requires explicit handling before you access the value.

Code That Triggers TS2532

// TS2532 examples

// Optional property access
interface Config {
  timeout?: number;
}
function run(cfg: Config) {
  const doubled = cfg.timeout * 2;
  // Error: Object is possibly 'undefined'
}

// Array.find returns T | undefined
const item = items.find(i => i.id === targetId);
console.log(item.name); // Error: Object is possibly 'undefined'

// Optional function parameter
function greet(name?: string) {
  console.log(name.toUpperCase()); // Error: Object is possibly 'undefined'
}

How to Fix TS2532

Option 1: Check for undefined before use

if (cfg.timeout !== undefined) {
  const doubled = cfg.timeout * 2; // OK
}

Option 2: Provide a default with ?? or ||

const timeout = cfg.timeout ?? 3000; // default 3000 if undefined
const doubled = timeout * 2; // OK

Option 3: Optional chaining to safely access nested props

const item = items.find(i => i.id === targetId);
console.log(item?.name); // OK — undefined if item is undefined

Frequently Asked Questions — TS2532

What does TS2532 mean?

TS2532 means you're accessing a property or method on a value TypeScript knows might be undefined. You must handle the undefined case — either check for it, provide a default, or use optional chaining.

TS2532 on Array.find — how to fix?

Array.find returns T | undefined. Either check: if (item) { ... }, or provide a fallback: const item = arr.find(...) ?? defaultItem.

TS2532 on optional parameters — how to fix?

Check the parameter inside the function: if (name !== undefined) { name.toUpperCase() }. Or provide a default: function greet(name = 'World') { ... }.

What is the difference between TS2532 and TS2531?

TS2531 is 'possibly null', TS2532 is 'possibly undefined'. The fixes are the same — guard against the nullish value before use. Both disappear when you narrow the type.

Can I use ! to suppress TS2532?

Yes — the non-null assertion (item!) tells TypeScript the value is not undefined. But if it actually is undefined at runtime, you'll get a TypeError. Only use ! when you're certain.

Convert JavaScript to TypeScript automatically

Paste your JS code and get type-annotated TypeScript — including fixes for common type errors — in seconds.

Try the converter →

Other TypeScript Errors

From the blog

View all →