Index signature
Describes objects whose property names are not known ahead of time.
Syntax
{ [key: string]: ValueType } Examples
interface StringMap {
[key: string]: string;
}
const headers: StringMap = { 'Content-Type': 'text/html' };
interface NumberDict {
[id: number]: { name: string };
}
Notes
An index signature allows arbitrary keys of type `string`, `number`, or
`symbol`. All declared properties must be assignable to the index value type.
Accessing an unknown key returns the value type (not `undefined`) unless
`noUncheckedIndexedAccess` is enabled. `Record<K, V>` is often clearer.