Repository navigation
Spread operator fails to distribute over union when recursive type call is inlined instead of aliasedΒ #62812
Copy link
Copy link
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional typesHelp WantedYou can do thisYou can do this
Milestone
Description
Activity
RyanCavanaugh commented
on Dec 1, 2025 MemberMore actionsπ€ Thank you for your issue! I've done some analysis to help get you started. This response is automatically generated; feel free to π or π this comment according to its usefulness.
Similar Issues
Here are the most similar issues I found
- (71%) microsoft/typescript#61753: Unexpected differences in distribution over union types: type string | 5 behaves differently than type string | [5]
- (70%) microsoft/typescript#28813: Array spread creating wrong union-ish type when spreading union of arrays
- (70%) microsoft/typescript#58645: Lose generic when spreading `T | undefined` where T is a generic object type
- (70%) microsoft/typescript#54910: Type instantiation is excessively deep with tuple spread
- (70%) microsoft/typescript#44850: Different behavior exhibited between homomorphic mapped types
- (69%) microsoft/typescript#54745: Spreading a discriminated union in a narrowing block widens it back
- (69%) microsoft/typescript#42771: Union type resolving to one side of the union when spread operator is used
- (68%) microsoft/typescript#41184: Discriminating union literal with spread operator gives type error
- (68%) microsoft/typescript#50922: Object spread with ternary causes invalid union on property
- (68%) microsoft/typescript#49802: Spread operator should not have worse ergonomics than `apply` - unexpected error spreading a union-of-tuples
- (68%) microsoft/typescript#45600: Contextual type doesn't apply to elements of array literal spread into another array literal
- (68%) microsoft/typescript#56185: UnionToIntersection not returning an object type
- (68%) microsoft/typescript#43787: Tuple types are spread incorrectly/ inconsistently on unions
- (67%) microsoft/typescript#57156: Union of tuples called out as not spreadable.
- (67%) microsoft/typescript#28191: Spread operator with one union-typed key gives type error?
If your issue is a duplicate of one of these, feel free to close this issue. Otherwise, no action is needed.
- addedHelp WantedYou can do thisYou can do thisDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional types
on Dec 1, 2025 - added a commit that references this issue
on Dec 4, 2025 - added a commit that references this issue
on Dec 15, 2025
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional typesHelp WantedYou can do thisYou can do this
π Search Terms
distribution, spread
π Version & Regression Information
This is the behavior in every version I tried from version 4.1.5 upwards to 5.9.3 and in nightly v6.0.0-dev.20251127
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.9.3#code/C4TwDgpgBAwgTgewM5IAqICYFcDGwA8AqgHYCWCxANLAlscBHFBAB4PEZJR0DWxCAd2IBtALoA+KAF4AUFHk06DJq3acow0sQBmjKAC1GCagDozW3UwBKEJMFFyFAfigAKEuWLM2EDlwt6ALIQALYARoyOCs4aweGMpmbwyGiYuAQeFNQ2duIO0dEAXFDEEABujACUUVDFYgDcMgA2EMBQDHYAjMXJKOgI2Hj4xFjxTAA+UHZwWgDm1MJ0GBDaWhAYEvXyAPTbGtNzolCTwiNjDqCQUAAiEGDAABad0rCIfWlDZxETU8AzxPMNEsVmsNpJdvs-odjhovowHC02h1gAAmYquOE-A4A7xqfw6PSZLwudxkCi43zqXj8IRQFzCImJEy3e5PUTFUoVOCVWolcpVLYQ4TYwEio4nTHUTHiyH-QHSmGnUbfahi5qtdq2YAAZnRmJhIopfigASYRLpbnNqkpXGpgmJGkZUDMJl6qQG6WGyr0kxFC2Bq1KYPZfK5PI5-O5Wx2e2FUIBqvjsxlSrGUu9cARGuRABY9RmDUmjepTVBzSSrT5jXbafSnS7XHG5SnpZUQ5yqryO1GoEK-b9m4rJSUMyn+wqJRnE82ZEA
π» Code
π Actual behavior
The types of test2 and test4 evaluate to the correct, expected, fully distributed type, while the type of test3 is incompletely distributed (as displayed by IntelliSense in the Playground).
The only difference between test2 and test3 is that in test3 the type that is aliased as Depth1 in test2 is inlined in test3. Thus, both should evaluate to the same type. The type of test2 is correct.
test4 also evaluates correctly. Here the alias is replaced by the literal evaluation result.
π Expected behavior
The type of variable test3 should evaluate to
[string, string] | [number, number] | [string, number] | [number, string]
But it evaluates to
[string, string] | [number, number]
Additional information about the issue
This problem matters since the recursive call in test3 is what I actually need for the construction of a respective recursive type.