Q38. What is noUncheckedIndexedAccess?
This compiler option makes indexed access types account for the possibility that a key or index is absent, often adding undefined to reads from arrays and index signatures. It encourages bounds and existence checks instead of assuming every lookup succeeds.
Even if an array is typed string[], items[10] may be undefined at runtime when the array is shorter than expected.
Note
Interview approach: define the concept, explain why it matters, then mention one trade-off or limitation.
TypeScript concept
// Illustrative TypeScript contract
type Identifier = string;
const id: Identifier = "item-1";💡 The example demonstrates the compile-time contract discussed in this question.
Key Takeaways
- Explain the concept in your own words.
- Know the practical trade-off and its limits.
- Use a small example to demonstrate the idea.
Knowledge Check
What is the safety benefit of this option?