- Notifications
You must be signed in to change notification settings - Fork13.2k
Fix spread operator failing to distribute over union when type is inlined#62836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
thromel wants to merge1 commit intomicrosoft:mainChoose a base branch fromthromel:fix/spread-tuple-union-distribution
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+436 −2
Conversation
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
Author
thromel commentedDec 4, 2025
@microsoft-github-policy-service agree |
Author
thromel commentedDec 10, 2025
…inedFixesmicrosoft#62812When a union/intersection type like `number | string` appears in the truebranch of a conditional type that has the same type as its check type,the type was incorrectly being narrowed with a substitution constraint.This caused issues when the union type was used as a type argument toa generic type - different occurrences of `number | string` in the codewere being treated as the same entity when they should be independent.The fix adds a check to skip this narrowing for structural types(unions/intersections) that don't contain type variables. Named types(interfaces, classes, etc.) still get narrowed since different referencesto the same named type refer to the same entity.
f44ce00 to8d6b841CompareSign up for freeto 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.
Fixes#62812
Problem
When a union/intersection type like
number | stringappears in the true branch of a conditional type that has the same type as its check type, the type was incorrectly being narrowed with a substitution constraint. This caused issues when the union type was used as a type argument to a generic type.For example:
Root Cause
In
getConditionalFlowTypeOfType, when processing a type node in the true branch of a conditional type, the function checks if the type matches the conditional's check type and creates a substitution type with the implied constraint.The issue is that for structural types like
number | string, different occurrences in the code all resolve to the same canonical type. So whenCrossProduct<number | string, [undefined]>appeared inside the true branch ofnumber | string extends infer Union ? ..., the type argumentnumber | stringwas incorrectly being narrowed with the constraintUnioneven though it was a completely independent occurrence.Fix
Added a check to skip this narrowing for union/intersection types that don't contain type variables:
This ensures:
Test
Added
tests/cases/conformance/types/spread/spreadTupleUnionDistribution.tsto verify the fix.