Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10 - Tuple to Union #32140

Open
joyanedel opened this issue Feb 8, 2024 · 0 comments
Open

10 - Tuple to Union #32140

joyanedel opened this issue Feb 8, 2024 · 0 comments
Labels
10 answer Share answers/solutions to a question en in English

Comments

@joyanedel
Copy link

joyanedel commented Feb 8, 2024

type TupleToUnion<T extends readonly any[]> = T extends [infer F, ...infer R] ? F | TupleToUnion<R> : never

We take the first element of the array T and union it to the rest of the elements once their type was recursively extracted

Another solution, cleaner that previous one is the next:

type TupleToUnion<T extends readonly any[]> = T[number]
@joyanedel joyanedel added answer Share answers/solutions to a question en in English labels Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10 answer Share answers/solutions to a question en in English
Projects
None yet
Development

No branches or pull requests

1 participant