I'm trying to figure out why the compiler doesn't infer A as a union type like string[] | number[]
when it fails. Instead, A is inferred as the first return value, which in this case is string[]
. Is there a solution to this issue?
const define = <A>({ handler }: { handler: (some: boolean) => A[] }) => ({ handler });
const a = define({
handler: (some: boolean) => {
if (some) {
return ["foo", "bar"];
} else {
return [1, 2];
}
},
});