I actually think this is a bug, but I thought I'd ask. I have a function. If passes a single number, I want to perform an operation that returns two objects. If it receives two numbers, I want to return one object. This looks like this now:
function split (splitAt: number | [number, number]): SomeSplittableObject | [SomeSplittableObject, SomeSplittableObject]
but with overloading I should be able to do this:
function split (splitAt: number): [SomeSplittableObject, SomeSplittableObject]
function split (splitAt: [number, number]): SomeSplittableObject
function split (splitAt: number | [number, number]): SomeSplittableObject | [SomeSplittableObject, SomeSplittableObject] {
// ... Implementation
}
let splitAt: number | [number, number] //... some variable
split(splitAt)
but I get an in-editor error
No overload matches this call.
Overload 1 of 2, '(splitAt: [number, number]): SomeSplittableObject', gave the following error.
Argument of type 'number | [number, number]' is not assignable to parameter of type '[number, number]'.
Type 'number' is not assignable to type '[number, number]'.
Overload 2 of 2, '(splitAt: number): [SomeSplittableObject, SomeSplittableObject]', gave the following error.
Argument of type 'number | [number, number]' is not assignable to parameter of type 'number'.
Type '[number, number]' is not assignable to type 'number'.
even if I cast splitAt as any in the implementation args I get the error