I am working on a library where a list of rules get's defined. I want to turn this list of rules into an interface for something to abide by the rules.
I end up getting a list that is similar to this in structure:
const rules = [
{} as { foo: 1 | 2 | 3},
{} as { bar: 4 | 5 | 6},
]
type T = typeof rules
The type of T
ends up being union array like so:
type T = ({
foo: 1 | 2 | 3;
} | {
bar: 4 | 5 | 6;
})[]
But what I actually want is an interface that merges them:
type T = {
foo?: 1 | 2 | 3
bar?: 4 | 5 | 6
}
Is there any way to achieve this?