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
- Check for undefined before using: if (arr[0] !== undefined) { use(arr[0]) }
- Use optional chaining: arr[0]?.property
- Provide a fallback: const item = arr[0] ?? defaultValue
- 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.
