Skip to content

noUncheckedIndexedAccess does not narrow properly when iterating with for...inΒ #58082

Closed as not planned
@ItsHarper

Description

@ItsHarper

πŸ” Search Terms

"noUncheckedIndexedAccess"

βœ… Viability Checklist

⭐ Suggestion

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.

⏯ Playground Link

Playground link

πŸ“ƒ Motivating Example

Iterating through a Record with non-null/undefined values with noUncheckedIndexedAccess enabled will no longer force handling of undefined

πŸ’» Use Cases

Without this change, I have to either leave noUncheckedIndexAccess disabled, or add unnecessary boilerplate whenever I'm iterating through a Record.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions