Vocabulary: Index signature

In TypeScript, an index signature (also known as an indexable type) allows you to define the types of properties that are not known in advance but can be accessed using square bracket notation. Index signatures are particularly useful when working with objects that have dynamic property names. (from ChatGPT)

interface MyObject {
  [key: string]: number;
}

const myData: MyObject = {
  apple: 5,
  banana: 3,
};

console.log(myData.apple); // Output: 5
console.log(myData.banana); // Output: 3