type-fest icon indicating copy to clipboard operation
type-fest copied to clipboard

`UnionToUnorderedTuple` type

Open sindresorhus opened this issue 6 months ago • 2 comments

I think it's worth adding this as long as we clearly document its downsides.

Initial attempt in https://github.com/sindresorhus/type-fest/pull/686

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

sindresorhus avatar Feb 22 '24 06:02 sindresorhus

We basically want to do what's described here, right? https://stackoverflow.com/a/55128956

Any other techniques?

voxpelli avatar Feb 22 '24 10:02 voxpelli

Basically:

  1. Convert union values to return values of functions
  2. UnionToIntersection to make it an intersection
  3. Intersection will be treated as a function overload from which the base return value (the last one in the original union) can be easily extracted
  4. Add that extracted last value to the the tuple result we want
  5. Repeat everything again with the remaining values that has not yet been extracted, adding one more item to the tuple for every iteration

voxpelli avatar Feb 22 '24 10:02 voxpelli