-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intersection, Union depends on type variable instantiation order #56906
Comments
The issue may be that |
Generally speaking, both union and intersection type operators are commutative (with the exception of function intersections, which are treated as overloads and are order-dependent), and any union/intersection containing |
@fatcerberus gotcha.
I think it would be logically consistent for either:
Why should the former be overriding? I was unable to find docs that make this clear, but it feels like an important design choice. Edit: I can see that the intent was for type T32<T> = never extends T ? true : false; // true
Edit again: my understanding current behavior for distributive conditional was wrong. It only distributes when the left-hand side is a type parameter. |
Specifically, a naked type parameter. Stuff like |
Oy. You’re right. And I can’t figure out when that’s a bug or a feature. For instance There’s also the curious case that even when the LHS does not contain a type parameter, when the LHS is |
Yeah, that’s a separate behavior from distribution and is intentional. |
Yes, it’s intentional. The reason for it ( |
🔎 Search Terms
generic type variable intersection union order
🕗 Version & Regression Information
⏯ Playground Link
Workbench Repro
💻 Code
🙁 Actual behavior
The types
UA0
,UA1
are resolved asany
andUA2
is resolved asunknown
. These all map down to the same union ofunknown
andany
, so should all be the same type.The types
AN0
,AN2
are resolved asnever
andAN1
resolved asany
. These all map down to be the intersection ofany
andnever
, so should all be the same type.🙂 Expected behavior
I expect
UA0
,UA1
andUA2
to resolve as the same type (probablyany
, but preferablyunknown
)I expect
AN0
,AN1
andAN2
to resolve as the same type (probablynever
)Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: