I have the following definition:
function foo(arg: number[] | number) {
if (Array.isArray(arg)) {
return [1]
}
return 0
}
I would expect typescript to figure out automatically what the return type is. Because of the type guard isArray() it knows if arg is an Array and can show the return type as number[]. However, using foo(...) shows its return value as number[] | 0 even when passing an array.
foo([]).push() // error because push doesnt exist on type 0
Is this a design limitation, a bug, just not implemented yet, or some other issue?