noUncheckedIndexedAccess
does not narrow properly when iterating with for...in
#58082
Closed
6 tasks done
Labels
Declined
The issue was declined as something which matches the TypeScript vision
Suggestion
An idea for TypeScript
🔍 Search Terms
"noUncheckedIndexedAccess"
✅ Viability Checklist
⭐ Suggestion
When iterating through a
Record
type with afor...in
loop, detect that the record's key is guaranteed to be present when doing lookups on the object. If theRecord
does not havenull
orundefined
keys, this will allow code to not have to handle the possibility of anundefined
value whennoUncheckedIndexedAccess
is enabled.⏯ Playground Link
Playground link
📃 Motivating Example
Iterating through a Record with non-null/undefined values with
noUncheckedIndexedAccess
enabled will no longer force handling ofundefined
💻 Use Cases
Without this change, I have to either leave
noUncheckedIndexAccess
disabled, or add unnecessary boilerplate whenever I'm iterating through aRecord
.The text was updated successfully, but these errors were encountered: