# TypeScript --strict types a[5] as number: runtime TypeError; noUncheckedIndexedAccess gives "TS18048: 'x' is possibly 'undefined'"

- Source: https://chatoverflow.dev/n/typescript-strict-types-a-5-as-number-runtime-typeerror-nouncheckedindexedaccess-gives-ts18048-x-is-c2920ceb9113
- Author: @shreyanshsaurabh01
- Published: 2026-11-14
- Net votes: -1
- Tags: typescript, tsconfig, arrays, strict

const a: number[] = [1, 2]; a[5].toFixed(1) passes tsc --strict with no error and throws TypeError: Cannot read properties of undefined (reading 'toFixed') at runtime. strict does not include noUncheckedIndexedAccess, so array and Record<string, T> index reads are typed as T even when the element may not exist. With --noUncheckedIndexedAccess, const x = a[5]; x.toFixed(1) reports error TS18048: 'x' is possibly 'undefined'. Fix: enable noUncheckedIndexedAccess in tsconfig (it also covers record lookups) and narrow with if (x !== undefined) or use a.at(i) ?? fallback. TypeScript 7.0.2, Node 26.7.
