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
noUncheckedIndexedAccess does not narrow properly when iterating with for...inΒ #58082
When iterating through a Record type with a for...in loop, detect that the record's key is guaranteed to be present when doing lookups on the object. If the Record does not have null or undefined keys, this will allow code to not have to handle the possibility of an undefined value when noUncheckedIndexedAccess is enabled.
changed the title [-]Allow iterating through a Record with `noUncheckedIndexedAccess` enabled without having to handle `undefined`[/-][+]`noUncheckedIndexedAccess` does not narrow properly when iterating with `for...in`[/+]on Apr 4, 2024
Could you edit to talk about index signatures instead of Records? A Record<K, V> isn't required to have an index signature (e.g., Record<"a", string>).
constarr=[1,2,3,4,5];for(constidxinarr){arr.length=0;// n.b. might be an indirect side effect of other code!constm=arr[idx];}
Which would give you a wrong type at m
We don't intend to make noUncheckedIndexedAccess any smarter than it already is - nearly any attempt to make it smarter induces soundness holes in one case or another, and the point of the flag was to not have any indexing holes.
Activity
ItsHarper commentedon Apr 4, 2024
A similar case to this was reported as #43614, and resolved in #51653.
[-]Allow iterating through a Record with `noUncheckedIndexedAccess` enabled without having to handle `undefined`[/-][+]`noUncheckedIndexedAccess` does not narrow properly when iterating with `for...in`[/+]jcalz commentedon Apr 4, 2024
Could you edit to talk about index signatures instead of
Records? ARecord<K, V>isn't required to have an index signature (e.g.,Record<"a", string>).RyanCavanaugh commentedon Apr 4, 2024
You could still write
Which would give you a wrong type at
mWe don't intend to make
noUncheckedIndexedAccessany smarter than it already is - nearly any attempt to make it smarter induces soundness holes in one case or another, and the point of the flag was to not have any indexing holes.ItsHarper commentedon Apr 4, 2024
Gotcha, that's fair. Thanks for responding!