Bug Report
๐ Search Terms
array index element undefined
๐ Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about type of element selected from (potentially) empty array
โฏ Playground Link
Playground link with relevant code
๐ป Code
const ary: string[] = [];
const firstElement = ary[0];
// `firstElement`'s type is `string` while it should be `string | undefined`
// or even better `undefined` since that can be deduced from the line above.
๐ Actual behavior
firstElement is of type string.
๐ Expected behavior
firstElement should be of type string | undefined or undefined if that can be deduced.