You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Potentially-undefined value not flagged when destructuring union of empty tuple and arrayΒ #61424
When destructuring a value whose type is an array, an empty tuple, and a non-empty tuple, the destructured value isn't flagged as possibly undefined which caused a runtime error. The value is correctly flagged as possibly undefined when accessing it by index.
π Expected behavior
When destructuring a value whose type is an array, an empty tuple, and a non-empty tuple, the destructured value should be flagged as potentially being undefined.
Additional information about the issue
This seems related to #55661 except, in this case, the union contains a mix of tuples and an array.
Even with noUncheckedIndexAccess off, the index access in the snippet works correctly: b could be undefined and TS correctly raises an error when I try to call toString. It's the destructuring behavior that seems incorrect since there's no error trying to call toString when there should be.
EDIT: I suppose it's not accurate for me to say the index access works "correctly" when noUncheckedIndexAccess is off (as in the snippet). Rather, it works "intuitively" but I'm not sure what "correct" behavior would look like here since arrays and tuples would individually behave differently.
Activity
MartinJohns commentedon Mar 14, 2025
You need to enable
noUncheckedIndexedAccess. That's what the flag is there for.RyanCavanaugh commentedon Mar 14, 2025
Still weird that the destructuring behavior is different though.
bthall16 commentedon Mar 14, 2025
Even with
noUncheckedIndexAccessoff, the index access in the snippet works correctly:bcould beundefinedand TS correctly raises an error when I try to calltoString. It's the destructuring behavior that seems incorrect since there's no error trying to calltoStringwhen there should be.EDIT: I suppose it's not accurate for me to say the index access works "correctly" when
noUncheckedIndexAccessis off (as in the snippet). Rather, it works "intuitively" but I'm not sure what "correct" behavior would look like here since arrays and tuples would individually behave differently.Andarist commentedon Mar 14, 2025
An extra bug related to this:
Actual
.d.tsemit:Expected
.d.tsemit: