I am working with an array that has multiple objects containing functions foo
.
My goal is to create a new object signature with a function foo
that inherits all the 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>
However, I am facing an issue where the result I'm getting is:
type U = {
foo: ((a: "a") => "A") | ((a: "b") => "B");
}
These conflicting signatures are making the function not callable. Is there a way to achieve (AND instead of OR) like this:
type U = {
foo: ((a: "a") => "A") & ((a: "b") => "B");
}
?