Bug Report
๐ Search Terms
noUncheckedIndexAccess, array
๐ Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about noUncheckedIndexAccess
โฏ Playground Link
Playground link with relevant code
๐ป Code
With noUncheckedIndexAccess enabled:
const arr: string[] = [];
type IncorrectArrayType = typeof arr[0]; // string
// there's a workaround, but it involves runtime overhead
const correct = arr[0];
type CorrectArrayType = typeof correct; // string | undefined
๐ Actual behavior
Indexing an array type doesn't include undefined with noUncheckedIndexAccess enabled
๐ Expected behavior
IncorrectArrayType should be string | undefined