Problem Statement
Make indexing safer against missing values:
Explanation
With this flag on, reading arr[i] is typed as possibly undefined unless the code proves otherwise. This prevents many out-of-bounds mistakes.
Code Solution
SolutionRead Only
// tsconfig.json
{
"compilerOptions": {
"noUncheckedIndexedAccess": true
}
}
// const x = arr[10]; // x: T | undefined