Skip to content

types.union only supports up to 9 arguments for correct typing result #2083

Answered by limbosounds
limbosounds asked this question in Q&A
Discussion options

You must be logged in to vote

Hello and thank you for your response!
This issue has a workaround:

types.union(
    types.union(
        // ...up to 9 types
    ),
    types.union(
        // ...up to 9 types
    ),
    // ...up to 9 unions
)

This workaround supports up to 81 types in total and resulting type is just the same as if it was a plain union.
So, it's kinda suitable for me despite looking schizophrenic 🤣

I tried to discover the source of this issue, and seems like it is in types.union definition
It has 33 overloads, and each next has more generic types than previous
Simplified example

declare function union<T1>(model1: T1)
declare function union<T1, T2>(model1: T1, model2: T2)
declare function union<T1, T2, T3>

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@limbosounds
Comment options

Answer selected by coolsoftwaretyler
@coolsoftwaretyler
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants