Skip to content
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

feat(core): add XOR type for mutual exclusion typing #1159

Closed
wants to merge 2 commits into from

Conversation

damienwebdev
Copy link
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Currently, we don't have any legible way to describe a Disjoint type.

Fixes: N/A

What is the new behavior?

This adds a new XOR type that we can use to describe our interfaces a bit better.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Derived from microsoft/TypeScript#14094 (comment)

@damienwebdev damienwebdev changed the title feat(core): add XOR type for mutually exclusion feat(core): add XOR type for mutual exclusion typing Nov 24, 2020
@damienwebdev damienwebdev deleted the xor_type branch January 4, 2021 15:59
@yard2010
Copy link

Honest question - why is this closed and not merged? Can I do anything about it?

@griest024
Copy link
Member

I don't remember exactly but I believe we didn't have a use case for it.

@griest024
Copy link
Member

griest024 commented Mar 11, 2021

@damienwebdev Do you remember why this was closed? Were there problems with the type behavior?

@yard2010 The code is MIT licensed so feel free to use it somewhere else if you want. Just be sure to give proper credit (note the comment in the TS repo).

@yard2010
Copy link

This is embarrassing - I have just realised that this is not the official typescript repo! I got here from this typescript issue and I didn't understand I left the repo. Anyway, thanks for the permission to use it and good luck with what you're doing, it looks fantastic.

@griest024
Copy link
Member

good luck with what you're doing, it looks fantastic.

Tell your friends 😁

@damienwebdev
Copy link
Member Author

A comment here, because I came to this conclusion long ago. The XOR type is an anti-pattern that should instead be replaced with a discriminable union. You should "kind" your types with a string kind and discriminate on the kind.

My XOR type works, but goes against what the typescript team is in favor of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants