-
Notifications
You must be signed in to change notification settings - Fork 59
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 types #46
Conversation
I'm curious whereas Another option would be to use |
The intersection of two structures is the structure containing the union of their fields. I tried to explain this here: HaxeFoundation/haxe#7006 (comment) |
Funny how we both get confused by the terminology. I think this always initially confuses people who tend to think "in rectangles". The misconception is that the rectangles are assumed to be the fields, and their intersection would then be their common fields. However, the correct interpretation is that the rectangles are (compatible/assignable/unifyable) types, and the intersection is then the types which are (compatible with/assignable to/unifyable with) every type making up the intersection. Conversely, the union of two structure types would be those types that can be assigned to type 1 or (not xor) type 2, i.e. types that have the fields of one or ( All this is a natural consequence of the fact that we allow assigning smaller structures to larger ones. Note that I don't want to make the terminology of intersection types very prevalent. It would likely only show up in the error message and the ComplexType constructor name. For all intents and purposes, this feature works like I have updated the proposal to mention future possibilities regarding interfaces. |
I can't emphasis enough to take a look at Typescript definitions of unions / intersections / etc.. |
ok for me |
I find intersection types and unions useful in some situations, and while of course this proposal's functionality is a bit limited, it doesn't seem to restrict future enhancements, so let's do it! \o/ |
Support
Type1 & Type2
intersection type syntax.Rendered version