Problem Statement
Discuss noPropertyAccessFromIndexSignature and when you’d enable it.
Explanation
This flag forces bracket access for properties coming from an index signature. It avoids false confidence when a key may not actually exist. Enable it for libraries and large apps where accidental `obj.someKey` on `{ [key: string]: T }` can hide bugs. You’ll write `obj['someKey']`, which reminds you the key is dynamic and may be missing.
Code Solution
SolutionRead Only
// tsconfig.json
{
"compilerOptions": { "noPropertyAccessFromIndexSignature": true }
}
type Dict = { [k: string]: number };
const d: Dict = {};
// d.foo = 1; // ❌ with the flag on
d['foo'] = 1; // ✅ explicit bracket access