I'm working with a function that returns a union type of tuples. I need to pass this return value to another function that can accept all its forms using the spread operator ...
.
type TupleUnion = readonly [number, number] | readonly [number, number, string]
function getTuple() : TupleUnion
function calc(a, b, c?)
const tuple = getTuple();
calc(...tuple)
However, when I try to do this, the Typescript compiler gives me an error:
A spread argument must either have a tuple type or be passed to a rest parameter.ts(2556)
I don't want to redefine the calc
function. Is there a way for the getTuple function to return a union type that supports the spread operator?