ProjectStack
typescript

TS18048: 'X' is possibly 'undefined'

TypeScript's noUncheckedIndexedAccess option is enabled and you're using an array element or object value without first confirming it exists. When this option is on, array indexing and object record access returns T | undefined instead of T.

Common causes

  • noUncheckedIndexedAccess is enabled in tsconfig.json (common in strict projects)
  • Accessing arr[0] directly when the array might be empty
  • Accessing a value from a Record<string, T> by key without checking if the key exists
  • Using an array index calculated at runtime without bounds checking

How to fix it

  1. Check for undefined before using: if (arr[0] !== undefined) { use(arr[0]) }
  2. Use optional chaining: arr[0]?.property
  3. Provide a fallback: const item = arr[0] ?? defaultValue
  4. Destructure with a default: const [first = defaultValue] = arr

Example

const items = ['a', 'b', 'c']; const first = items[0]; console.log(first.toUpperCase()); // error TS18048: 'first' is possibly 'undefined'.

Array element access when noUncheckedIndexedAccess makes the result T | undefined

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.