ProjectStack
typescript

TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Y'

You're using a dynamic string value to access a property on an object, but the object's type doesn't have an index signature allowing arbitrary string keys. TypeScript can't determine what type the result will be.

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

  1. Add an index signature to the type: interface MyObj { [key: string]: string }
  2. Use a Record type for objects used as dictionaries: Record<string, ValueType>
  3. Narrow the key type: if the keys are limited, type them as a union: 'a' | 'b' | 'c'
  4. 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.