Sometimes you don’t know property names in advance. An index signature says: any string key is allowed, and its value has one of a few types. This is useful for settings, flags, or small dictionaries.
interface Flags {
[key: string]: boolean;
}You will count how many settings are turned on.
Count enabled flags in a settings object.
interface Settings { [key: string]: string | number | boolean }.countEnabled(s: Settings): number that returns how many values are exactly true.0 when the object has no keys.