What I need
I have an undetermined number of mods in an input object:
const mod1 = {
actions: {
a() { },
b() { },
}
}
const mod2 = {
actions: {
c() { },
d() { },
}
}
const input = {
mods: {
mod1,
mod2
}
}
At run time, a lib merges the mods in a single object which is equivalent to:
const output = {
actions: {
a() { },
b() { },
c() { },
d() { },
}
}
And I would like to create a type that would describe this single object.
What I tried
The input objects can be described like that:
interface Input {
mods: Mods
}
interface Mods {
[name: string]: Mod
}
interface Mod {
actions: {
[name: string]: () => void
}
}
Then, I don't know how to merge the content of mods:
interface ToOutput<I extends Input> {
actions: MergeMods<I["mods"]>
}
type MergeMods<M extends Mods> = // How to merge the content of 'M'?