-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Provide "remove from union" type operator #12959
Comments
might be a dup of #4183 |
@Aleksey-Bykov This is actually a distinct proposal. #4183 address the case where you wish for a type not to have specific members. This proposal instead addresses the case where you can know definitively that a value of a union type is definitely not one of a set of types. |
It's universal proposal for any 2 types being subtracted from each other,
including unions, if you read closer
…On Dec 15, 2016 5:00 PM, "Thomas Michon" ***@***.***> wrote:
@Aleksey-Bykov <https://github.com/aleksey-bykov> This is actually a
distinct proposal. #4183
<#4183> address the case
where you wish for a type not to have specific members. This proposal
instead addresses the case where you can know definitively that a value of
a union type is definitely not one of a set of types.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12959 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA5PzQw2NhbtorgjTgb4isPc0XLF9ywgks5rIbiTgaJpZM4LOnFz>
.
|
I hadn't seen #12215, mostly due to using the wrong search terms to look for duplicates. However, this proposal is slightly wider in scope, as it applies to union types in general. The main advantage this has over #4183 is that it is much narrower in scope and should therefore be much less work to implement. The type system already has logic to remove types from unions, since type guards do so, this proposal just allows the developer to request that operation when describing a type. |
We would be more in favor of the proposal in #12215. the operator is only applicable to literal types (which includes |
With the introduction of the
keyof
operator and mapped types, the ability to remove some subset of the types in a union becomes increasingly useful. The type system already supports this operation via type guards in control flow, but we have no way to describe the resulting type to the compiler.Available existing behavior
However, we have no way of specifying the type of
nsDir
in terms ofDirection
andEastWest
Proposal
We introduce a new "remove from union" operator
A -| B
(symbol choice subject to change) that has the following behavior:This will also allow us to solve some current proposals:
Edit: fixed variables in
provideA
, spacing@sandersn, @mhegazy
The text was updated successfully, but these errors were encountered: