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.