-
Notifications
You must be signed in to change notification settings - Fork 643
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
Improved typing for union types #2151
Improved typing for union types #2151
Conversation
b0cbda0
to
6c37a7f
Compare
6c37a7f
to
1503b4a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @thegedge - thank you again, so much, for this phenomenal work. I'm stoked to see how many issues it may resolve.
I left a few comments here. I have some minor suggestions and questions. Nothing blocking, so please feel free to either make those changes, or ask me to do it myself. I appreciate all the time you've already put into this.
As you mentioned, there are a few changes here that some folks may consider breaking. If anyone else sees this PR and has concerns, I'd love to hear that. We will bring it up at the Maintainer's meeting on March 7th. I expect we will release a pre-release version for folks to try out, but probably take our time with releasing it, to make sure we don't cause a lot of downstream churn for folks
47c0702 replicates #1833 - so I don't think this fixes that quite yet either, unless I've got something borked locally as in this comment |
Merge conflict came from #2152 since we're editing |
47c0702
to
abaa13c
Compare
Oh yeah, great call on regression tests for the issues we fixed! I'll double check on #1525 this evening |
@thegedge - I added a test for 1525, and it's failing in CI We definitely don't need to block on this, but since it looks like you've seen the fix for 1525 at some point, would be cool to try and verify it. Let me know whatcha think! |
I will remove that failing test and plan to merge this in sometime over the weekend unless I hear otherwise. |
Hey, @coolsoftwaretyler. Thanks for 👀. We have a big launch week coming up so I've been super busy and neglected to check in. If I can't get to it this evening, let's ignore and follow up with #1525 later. |
Perfect, thank you! |
6581544
to
7886cbb
Compare
Amended your test commit, was just missing an important check from the issue to ensure narrowing happens. In this PR, it passes! 🙇 for adding all these tests. I'll keep that in mind for future work. |
Phenomenal! I'll merge and then put out a pre-release build to npm, along with an RFC about how strict we want to be around semantic versioning here. |
What does this PR do and why?
After 9 or 10 types in a union, we devolve into an
IAnyType
. This isn't particularly useful, and potentially even dangerous (in a typechecking sense, given the behaviour ofany
).This PR makes union types become proper TS sum types for any number of member types given to the union. It also results in types that are much simpler to manage, since we don't have to "unroll" for each possible number of types. We've also brought similar improvements to
types.enumeration
.Steps to validate locally
I added some new tests for union and enumeration types, and verified that the tests fail before this change and pass after.