Using type packs in a tuple

(Follow-up for Union returns with type packs, since I believe my question was too case-based and confusing.)

I’m assuming this just isn’t a feature, but maybe somebody already knows how to do this? Basically, I can combine two generics into a tuple.

type T<A, B> = () -> (A, B)

-- () -> (number, boolean)
type func = T<number, boolean>

But this is not possible to do with type packs, even when separating the packs in ().

-- nope
type T<A..., B...> = () -> (A..., B...)

-- () -> (number, string, boolean, nil)
type func = T<(number, string), (boolean, nil)>

Anybody have a clue?

1 Like

I’m honestly really confused on what you’re asking…

Although I’m guessing you’re combining two sets of returned variables?

Basically it is not possible because tuples are not first class citizens in luau. No object would have type (number, string) for example.

() -> (A..., B...)

this is not allowed, because A... means none or many types. It is not known how many, so it would not be known when the B... types start. A generic type pack must be the last one in the list, (A, B...).

5 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.