-
Notifications
You must be signed in to change notification settings - Fork 38
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 with &? #132
Comments
I'm experimentally using withFlying = o => m: o & {
fly () => m,
land () => m,
isFlying () => Boolean
} In this example, I like this better than the |
What you are describing looks like a fluent API to me. Here's how I did it myself: API The consequence would be that a letter (as a name) always represent the same thing for the current interface. Can it be a literal? |
The letter
I'm not sure what you're asking. What is "it"? |
I was thinking of using the same letter again for a second signature. Id reckon it would be isolated from the first one.
Can we have an intersection which takes into account that some types cover literals and objects? In your example can the |
For that to work, typeclass WithFlying(o) = m: o & {
fly () => m,
land () => m,
isFlying () => Boolean
} Then you could reuse it like: withFlying = WithFlying W ~> o => W(o) You can read that as " |
|
By be I meant represent obviously. I was just checking if the distinction was required because Rtype doesn't make it. |
Rtype is a structural type system. It doesn't care how an interface is satisfied. Only that it is. That means literals automatically imply their full prototype interfaces. |
What you are trying to achieve here is an addition and not really an intersection per se. I don't like introducing new operators but |
We're already using an intersection in the docs: JSON::parse(String, reviver: Function)
=> !Function & !Void & !Symbol,
throws SyntaxError
// which is equivalent to
JSON::parse(String, reviver: Function)
=> !(Function | Void | Symbol),
throws SyntaxError But it isn't described. Both TypeScript and Flow use |
Flow's intersection docs are a good reflection of what I'm thinking for this syntax, however, on reflection, this should work equally well: withFlying = o => m: {
...o,
fly () => m,
land () => m,
isFlying () => Boolean
} That said, I still think we should add Does this make any sense? { ...!Function, ...!Void, ...!Symbol } I don't know if intersections work with negations. Do they? |
I was reluctant to the additions of new operators just for these uncommon use cases. How would you achieve subtraction using
If you are talking about the |
Which type notations support the difference (subtraction) or complement operations? I think anybody familiar with algebra would recognize the subtraction operator as set difference (types and sets are good analogs, IMO). That said, I think difference deserves it's own issue. ;) |
I wouldn't introduce
check #139 TL;DR: if we introduce
|
I think I'll write up a more detailed proposal of set operations and close this issue. |
You mean append, add, remove? |
I ran into a use case where object spread would not work and the
&
operator would have been very useful for intersection types (see#18#9). Were there any good reasons not to add it?The text was updated successfully, but these errors were encountered: