noUnCheckedIndexAccess adds undefined to any un-declared fields in a type. This is useful if you have an index signature and want to check if a property exists before accessing it.
This satisfies TypeScript because myKey is typed as string in the index signature of myObject. What we do not know yet is if myObject["myKey"] is defined for us to use.
With noUnCheckedIndexAccess enabled, TypeScript will warn us that the object is possibly undefined and that we should check it exists:
TypeScript Config: noUnCheckedIndexAccess
noUnCheckedIndexAccessaddsundefinedto any un-declared fields in a type. This is useful if you have an index signature and want to check if a property exists before accessing it.Take this example:
This satisfies TypeScript because
myKeyis typed asstringin the index signature ofmyObject. What we do not know yet is ifmyObject["myKey"]is defined for us to use.With
noUnCheckedIndexAccessenabled, TypeScript will warn us that the object is possiblyundefinedand that we should check it exists: