Manuel Schiller Manuel Schiller - 3 months ago 31
TypeScript Question

Interface for dynamic key in typescript

I have an Object like this that is created by underscore's

_.groupBy()
method.

myObject = {
"key" : [{Object},{Object2},{Object3}],
"key2" : [{Object4},{Object5},{Object6}],
...
}


How would I define that as an Interface with TypeScript?
i don't want to simply define it as
myObject:Object = { ...
but rather have an own type for it.

Answer

Your object looks like a dictionary of Object arrays

interface Dic {
    [key: string]: Object[]
}