Record from noUncheckedIndexedAccess: false can't be expressed when noUncheckedIndexedAccess: true #48917
Closed
5 tasks done
Labels
Duplicate
An existing issue was already created
Suggestion
Like with ways for adding and removing optionality form properties
?/-
there seams to be a need to remove the special undefinedness of properties introduced in noUncheckedIndexedAccess:true🔍 Search Terms
noUncheckedIndexedAccess Record Array
✅ Viability Checklist
My suggestion meets these guidelines:
📃 Motivating Example
With
noUncheckedIndexedAccess:false
we have a notion ofRecord
that defines values, for all the possible properties. In practice there are not many actual values like that. Point ofnoUncheckedIndexedAccess:true
was to automatically add| undefined
type to result of property access so we are more type-safe automatically.The main TypeSafe use-case for the records which do have value for any possible key are Proxies. And looks like we have lost a way to express the those properly with
noUncheckedIndexedAccess:true
💻 Use Cases
Imagine
with
noUncheckedIndexedAccess:false
, typer offoo
isstring
tho withnoUncheckedIndexedAccess:true
,foo
has type:string | undefined
which is not correct. here we know 100% that any value we read fromval
via property access, must bestring
, but it can't be expressed using Typescript whennoUncheckedIndexedAccess:true
.We can visualize what we lost using this table:
The text was updated successfully, but these errors were encountered: