-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Updates types to eliminate void-emitting channel pitfall #2296
Conversation
🦋 Changeset detectedLatest commit: 9515cc4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I'm unsure about the change because I'm not sure what the mentioned pitfall is. Could you back it up with some examples? The current types seem to be correct to me as this is a valid situation: TS playground |
Exactly, the types allow you to do what will end up with a runtime exception. In your example |
Do you want an example of that written in addition to yours and the several tests that are a part of this PR? |
Ah, I forgot about this runtime check:
Thanks for clarifying! I think that the original intention was there to avoid allowing I've done some testing ( |
Ok, added tests for covering primitives. Doing |
This is an extracted repro case for the mentioned problem with null: TS playground If we take a closer look at it and hover over function channel<{}>(buffer?: Buffer<{}> | undefined): Channel<{}> Of course, this just "propagates" further and we might see a similar result when hovering over (method) Channel<{}>.put(message: {} | END): void It acts as if declare function test<T extends {} | null>(): T
test() My guess is just that behavior in TS around this somehow changed a long time ago - which is interesting, cause this is the exact behavior that we might experience without I think that this particular test can just be omitted for those TS@<3.6 tests. |
Ok, sounds good. How do you disable the test? The failure's coming from the non-3.6 directory
I tried putting that minimum version comment at the top of the file but it doesn't seem to have an effect. |
Basically, those files are "sibling" files and for the most part, they are the same (and should be kept the same as much as possible):
The only difference between them is the minimum TS version they are tested against. I didn't fully confirm this but I think the non-ts3.6 files are still tested with TS@>=3.6. So to remove a "test" you should just remove the discussed assertion from the file in which it has been added. We should add this section of the changes to the |
K, done @Andarist |
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.
We just need some changesets here. Remember that you are not constrained to creating a single changeset per PR. I would probably add a single one for @redux-saga/types
here and the second one for @redux-saga/core
+redux-saga
(each describing the change from the perspective of the included packages)
I've run into the pitfall a few times recently of making a void-emitting event channel. I decided that it would be great if the types enforced that incompatibility instead of happily accepting the invalid type, hiding the bug until run time.