Skip to content

Conversation

@som-sm
Copy link
Collaborator

@som-sm som-sm commented Oct 6, 2025

The & Union bit in UnionToIntersection was added in #682, but the test case added along with it was incorrect.

? Intersection & Union

The test actually does nothing, as already pointed out in #682 (comment).

// It's possible to index by the resulting type.
type ObjectsUnion = {a: string; z: string} | {b: string; z: string} | {c: string; z: string};
declare const value: ObjectsUnion[UnionToIntersection<keyof ObjectsUnion>];
expectType<string>(value);

This PR adds a generic assignability test that correctly verifies the & Union change as it only passes when the change is present. The updated test case basically verifies that UnionToIntersection<T | U | ...> is assignable to T | U | ....

Thanks to @Beraliv for pointing this out in ts-essentials/ts-essentials#451 (comment).

@som-sm som-sm requested a review from sindresorhus October 6, 2025 10:09
@som-sm som-sm marked this pull request as ready for review October 6, 2025 10:09
Copy link

@Beraliv Beraliv left a comment

Choose a reason for hiding this comment

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

Thank you for responding so quickly, it makes sense to me now!

@sindresorhus sindresorhus merged commit 140b738 into main Oct 6, 2025
6 checks passed
@sindresorhus sindresorhus deleted the fix/union-to-intersection-test-case branch October 6, 2025 10:28
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.

4 participants