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
| Code | TS2532 |
|---|---|
| Message | Object is possibly 'undefined'. |
| TypeScript's category | error |
| Listed under | Null, 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
/** @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'.
}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 asitems[0]orbyId[id]includesundefined. strictNullChecks(part ofstrict) 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.
/** @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;
}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 (unlessnoUncheckedIndexedAccessis on), because an index read is typed as the element type.findis the honest version.- A cast or the
!operator would hide the error; in a.jsfile!is not even allowed (TS8013).
Sources
- Array.prototype.find() · MDN Web Docs
- TSConfig Reference: noUncheckedIndexedAccess · TypeScript
- diagnosticMessages.json (TypeScript 5.9.3) · TypeScript on GitHub
Last reviewed 20 October 2026.