Add UnionMember type#1368
Merged
sindresorhus merged 19 commits intosindresorhus:mainfrom Mar 18, 2026
Merged
Conversation
sindresorhus
requested changes
Feb 14, 2026
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
Contributor
Author
|
Thanks for your reviews! And I believe this suggestion implies that If so, type UnionToTupleWithExclude<T, L = LastOfUnion<T>> =
IsNever<T> extends false
? [...UnionToTupleWithExclude<Exclude<T, L>>, L]
: [];
expectType<1 | 2 | 3>({} as UnionToTupleWithExclude<1 | 2 | 3>[number]); |
som-sm
requested changes
Feb 15, 2026
LastOfUnion: export internal type, useful to recurse union-types. UnionMember: export internal type, useful to recurse union-types.
som-sm
requested changes
Mar 1, 2026
Collaborator
som-sm
left a comment
There was a problem hiding this comment.
PR mostly LGTM, just few minor comments.
4332fc5 to
1c642f4
Compare
som-sm
reviewed
Mar 2, 2026
som-sm
reviewed
Mar 2, 2026
som-sm
reviewed
Mar 2, 2026
Co-authored-by: Som Shekhar Mukherjee <49264891+som-sm@users.noreply.github.com>
Contributor
Author
|
Thank you!
Yes. |
som-sm
approved these changes
Mar 3, 2026
UnionMember: export internal type, useful to recurse union-types. UnionMember type
Collaborator
|
@sindresorhus If this LGTY, this can be merged. Also, #1349. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
UnionMemberAnd the current
UnionMember, which locally defined inUnionToTuple, returnsunknown.This would cause an error if end-users use
IsNeverfor termination check.Ideally,$A$ and $B$ are type arguments of $A \cup B$ -> $B$ , so $\emptyset$ -> $\emptyset$ intuitively ($\bot$ -> $\bot$ ).
UnionMemberreduces a type, e.g., assumingUnionMember<A | B>,This PR's
UnionMemberhandles this.Note
UnionToTuple: Fix behavior when a union member is a supertype of another; AddExcludeExactlytype #1349