filter noUncheckedIndexedAccess with own property check #41848
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
Search Terms
ownProperty
hasOwnProperty
noUncheckedIndexedAccess
type check
Suggestion
noUncheckedIndexedAccess
is a great feature. However, ts reports that object can beundefined
even withhasOwnProperty
check.I suggest that a
hasOwnProperty
check makes unchecked indexed accesses checked, and return the checked value.Use Cases
Since only
string
values are allowed inobj
, the only case such value isundefined
is when the key does not exist onobj
. The value ofobj[key]
can only bestring
. However, typescript still reports type ofobj[key]
beingstring | undefined
.Examples
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: