Common causes
- Accessing obj[dynamicKey] where obj is typed as a specific interface without an index signature
- Using a variable string as a key to look up properties on an object with known, fixed keys
- Mapping over Object.keys() and accessing values with the resulting key strings
- noImplicitAny or strict mode flagging the dynamic access
How to fix it
- Add an index signature to the type: interface MyObj { [key: string]: string }
- Use a Record type for objects used as dictionaries: Record<string, ValueType>
- Narrow the key type: if the keys are limited, type them as a union: 'a' | 'b' | 'c'
- Cast the key: obj[key as keyof typeof obj] — use when you're certain the key exists
Example
const config = { host: 'localhost', port: 3000 };
const key = 'host';
console.log(config[key]);
// error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ host: string; port: number; }'.Accessing an object with a dynamic string key when the type has no index signature
Browse more errors
The Developer Hub covers 150+ errors across Git, npm, Node.js, Python, TypeScript, and Docker — with plain-English explanations and fix steps.
