Posted on 2021-02-04 21:13:05+00:00
You have a function with different return types based on whether or not rest parameters are passed in. Maybe it's a fringe edge case, but you never know when you'll need it. Read on to find a way to statically type this use case.
First, we have our use case without rest parameters:
Now we want our version with rest parameters to return something else:
We can't have optional rest parameters in the first case, so the trick is to pass in an empty tuple, like so:
1 2 3 4 5 6 7 8 9 10 11 12
And that's it. You're done, with static typing through and through.
not sure about line 12