I have an array that contains multiple objects with functions foo
.
Now I want to construct a new object signature with a function foo
that inherits all signatures from the array item foo
functions.
let arr = [
{ foo: (a: 'a') => 'A' as const },
{ foo: (a: 'b') => 'B' as const },
];
type MapAndUnion<T extends ReadonlyArray<any>> = { foo: T[number] extends { foo: infer V } ? V : never }
type U = MapAndUnion<typeof arr>
unfortunately, I am getting
type U = {
foo: ((a: "a") => "A") | ((a: "b") => "B");
}
This is not callable, as the signatures are conflicting.
Is there a way to get (AND instead of OR)
type U = {
foo: ((a: "a") => "A") & ((a: "b") => "B");
}
?