Search⌘ K

String or Number Indexes

Explore how to define and use index signatures in TypeScript with string or number keys. Understand how to control dynamic object member types, apply generic types, and leverage strong typing for safer and more flexible object structures.

We'll cover the following...

The index signature can define members of an object with an identifier with square brackets.

myObject["memberName"] = "Value Here";

The identifier type can only be a string or a number. The identifier is the name between the brackets. In the previous example, it was memberName. In the following example, ...