You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don’t think that's possible, the type you suggested is a tuple, which is ordered. I suppose extends can be used to build a type like if x[0] is 'one', then x[1] must be 'two' | 'three', but that sounds extremely verbose and complex.
I think you could use the #686 type for this when it lands.
Untested ChatGPT generated:
typeT='one'|'two'|'three';typeAllMembersPresent<Union>=UnionToTuple<Union>extends infer Array
? (ArrayextendsUnionToTuple<Union>
? (UnionextendsArray[number] ? Array : never)
: never)
: never;typeE=AllMembersPresent<T>;constvalidArray: E=['one','three','two'];// This is validconstinvalidArray1: E=['one','three'];// This will throw a type errorconstinvalidArray2: E=['one','three','four'];// This will throw a type error
Say I have:
It would be great to generate a type,
E
that requires all union values, which in this case would be something like this but without enforcing order:Upvote & Fund
The text was updated successfully, but these errors were encountered: