How to define an interface for objects with dynamic keys?
Your object looks like a dictionary of Object
arrays
interface Dic {
[key: string]: Object[]
}
The typescript literature often refers to this pattern as "the description of an indexable object" with a general form
interface Dic {
[key: string|number]: object_type
}
or
type Dic = {
[key: string|number]: object_type
}
There's now a dedicated Record
type in TypeScript:
const myObject: Record<string, object[]> = { ... }
Also, consider typing the keys whenever possible:
type MyKey = 'key1' | 'key2' | ...
const myObject: Record<MyKey, object[]> = { ... }