Skip to content

IsUnion: Fix behavior when the entire union extends all individual members#1353

Merged
sindresorhus merged 5 commits intosindresorhus:mainfrom
taiyakihitotsu:fix/is-union-20260207
Feb 7, 2026
Merged

IsUnion: Fix behavior when the entire union extends all individual members#1353
sindresorhus merged 5 commits intosindresorhus:mainfrom
taiyakihitotsu:fix/is-union-20260207

Conversation

@taiyakihitotsu
Copy link
Contributor

@taiyakihitotsu taiyakihitotsu commented Feb 7, 2026

Close #1351

Comment on lines +20 to +23
type SuperTypeUnion =
{optionalField?: number; test1: number; test2: string}
| {test1: number; test2: string};
expectType<true>({} as IsUnion<SuperTypeUnion>);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
type SuperTypeUnion =
{optionalField?: number; test1: number; test2: string}
| {test1: number; test2: string};
expectType<true>({} as IsUnion<SuperTypeUnion>);
type TestUnion =
// Here, the entire union extends both the individual members:
// So, `TestUnion` extends `{opt?: number; a: number; b: string}`, and
// `TestUnion` extends `{a: number; b: string}`.
| {opt?: number; a: number; b: string}
| {a: number; b: string};
expectType<IsUnion<TestUnion>>(true);

This makes the test case more clear.

? false
: T extends any
? [U] extends [T]
? true extends IsEqual<[U], [T]>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
? true extends IsEqual<[U], [T]>
? IsEqual<U, T> extends true

U and T don't need to wrapped in a tuple anymore.

@som-sm som-sm changed the title fix: #1351 IsUnion IsUnion: Fix behavior when the entire union extends all individual members Feb 7, 2026
@taiyakihitotsu
Copy link
Contributor Author

@som-sm

Thanks for your quick reviews! Addressed!

@taiyakihitotsu taiyakihitotsu requested a review from som-sm February 7, 2026 17:25
@sindresorhus sindresorhus merged commit b0321a5 into sindresorhus:main Feb 7, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isUnion incorrect behavior

3 participants