TypeScript error

TS2532: A call that may return undefined, used without a check

  • Error TS2532
  • Reported with strictNullChecks
  • Reported with strict
  • Tested with TypeScript 5.9

error TS2532: Object is possibly 'undefined'. is reported when code reads a property of an expression whose type includes undefined. Array.prototype.find is the classic case: it returns undefined when nothing matches, so products.find(...).price has a path that throws.

Like TS2531 for null, this is the form without a name. Put the result in a variable and the error becomes TS18048. With noUncheckedIndexedAccess on, reading an array element by index (items[0].name) is reported the same way.

At a glance

CodeTS2532
MessageObject is possibly 'undefined'.
TypeScript's categoryerror
Listed underNull, undefined and unknown
Turned on by strictNullChecks, strict
In .js files Reported when the file is checked: checkJs in jsconfig.json, or // @ts-check at the top of the file

The message is TypeScript's own text from its diagnostic messages file (Apache-2.0).

What it looks like

catalog.js Error confirmed 5.9.3 TypeScript 5.9.3, run 21 October 2026: catalog.js(9,10): error TS2532: Object is possibly 'undefined'. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. catalog.js(9,10): error TS2532: Object is possibly 'undefined'. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. catalog.js(9,10): error TS2532: Object is possibly 'undefined'. checked 21 October 2026
/** @typedef {{ sku: string, name: string, price: number }} Product */

/** @type {Product[]} */
const products = [{ sku: "TEE-01", name: "Cotton tee", price: 19 }];

/** @param {string} sku */
export function priceOf(sku) {
  return products.find((p) => p.sku === sku).price;error TS2532: Object is possibly 'undefined'.
}
Reading a property of find()'s result.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["*.js"]
}

What causes it

  • A call that may return undefined (find, Map.prototype.get, at) is used directly.
  • With noUncheckedIndexedAccess, an index read such as items[0] or byId[id] includes undefined.
  • strictNullChecks (part of strict) is on.

How to fix it

Decide what happens when it is missing

Keep the result, test it, and either throw (when a missing item is a bug) or return a fallback (when it is expected). products.find(...)?.price ?? null does the second in one expression and documents it in the return type.

catalog.js TypeScript 5.9.3 TypeScript 5.9.3, run 21 October 2026: No errors. 6.0.3 TypeScript 6.0.3, run 21 October 2026: the same as 5.9.3. No errors. 7.0.2 TypeScript 7.0.2, run 21 October 2026: the same as 5.9.3. No errors. checked 21 October 2026
/** @typedef {{ sku: string, name: string, price: number }} Product */

/** @type {Product[]} */
const products = [{ sku: "TEE-01", name: "Cotton tee", price: 19 }];

/** @param {string} sku */
export function priceOf(sku) {
  const product = products.find((p) => p.sku === sku);
  if (!product) throw new Error(`Unknown product ${sku}`);
  return product.price;
}

/** @param {string} sku */
export function priceOrNull(sku) {
  return products.find((p) => p.sku === sku)?.price ?? null;
}
Handle the missing product, or say what happens instead.
jsconfig.json for this example
{
  "compilerOptions": {
    "checkJs": true,
    "noEmit": true,
    "strict": true,
    "target": "es2022",
    "module": "nodenext",
    "types": []
  },
  "include": ["*.js"]
}

Gotchas

  • filter(...)[0] has the same problem without the checker noticing (unless noUncheckedIndexedAccess is on), because an index read is typed as the element type. find is the honest version.
  • A cast or the ! operator would hide the error; in a .js file ! is not even allowed (TS8013).

Sources

Last reviewed 20 October 2026.