Closed as not planned
Closed as not planned
Description
π Search Terms
"noUncheckedIndexedAccess"
β Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
β 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
π 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
.