-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(Subject): make value parameter for next non-optional #3074
Conversation
Prevents emitting undefined on strictly-typed Subjects BREAKING CHANGE: If you are using TypeScript called next() without a value before, TypeScript will error. If the Subject is of type void, explicitely pass undefined to next(). closes ReactiveX#2852
Generated by 🚫 dangerJS |
Given that I've personally written a lot of code that calls Subject cc @kwonoj |
afaik there isn't great way. Thought of defeult generic bit, but neither |
I'm still thinking about this one. Consulting some TypeScript folks for a second opinion. FWIW: I'm totally on the fence about this change. |
I can't say whether this is intended, but
seems to work. However, it does also allow
where at least the latter is probably not ideal, but perhaps a good compromise. |
@Airblader Subject value type rely on class parameteric generic, I don't think we'll going to have function level generic param separately. For class generics, we can't have overload. |
Fair enough. For what it's worth, I'm not a fan of this change. void subjects are a frequent usecase and writing undefined explicitly looks and feels odd there. And that's on top of being a breaking change which will break a lot of codebases (admittedly the fix is simple). Having a non-generc VoidSubject type would be an option, but a separate type seems a bit extreme I guess. |
I've been thinking this bit, while I like explicitly of interface, there are still lot of cases of using I'd like to just suggest to make signature to |
Maybe we should open an issue at TypeScript to treat But for me, I would always choose type safety over not having to type |
Well, I do also prefer type safety. So say when we decided to have default param |
With |
I am saying |
@benlesh thoughts? I honestly bit indifferent around this matter, claritywise either would just work. One for breaking, one for not (and bit loosend as user still don't get enforce to supply param). |
My point is there is zero difference from a type safety perspective |
I think that's part I disagree. |
Current state: No compile error when sending in Where does the type safety come in? The runtime JS is slightly different, but that obviously doesn't make it more type safe. The signature is slightly different, which could be seen as part of "documentation". But nothing will actually prevent you from writing/committing/merging/deploying that bug. |
Your statement is based on interface asks As I commented in original issue, I am generally in favor of strong types with explicit clarity, but also it is somewhat widely used pattern of using subject as signal. If we have TSC support like this:
then I would be all for those, but unfortunately that doesn't seem to work with class based parametric generic but only work with function overload. |
But again, as said I'm bit indifferent in this matter (as myself strongly prefer explicit type, while my suggestion is workaround for widely-used pattern for subject). I'm trying to advocate those usecases with workaround proposals. |
Then you would have to change the |
Rock meet hard place. On the one hand, allowing implicit undefined values in for I can't really lean either way. The strongly typed developer in me wants to supply the value, the JavaScript developer in me wants to allow people to use the foot gun if they forget to pass a value. |
yeah, pretty much same @david-driscoll (guess reason we are having long threads here. 😅 ) |
Oh wow, actually digging bit more and found very similar proposal here: microsoft/TypeScript#12400 (comment) (copy-pasta here)
and this is accepted proposal, makes me thinking rather wait compiler side support. |
Ok, I'm closing this PR itself for now, and let's track this with upstream changes. When proposed change comes in, we can satisfy all conditions without breaking changes. |
It seems like TypeScript 2.8 conditional generics may solve this well according to @jasonaden. I'll hold off for that, because I'm not fond of this change, although I definitely understand the spirit of the change. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Prevents emitting undefined on strictly-typed Subjects
BREAKING CHANGE:
If you are using TypeScript called next() without a value before, TypeScript will error. If the Subject is of type void, explicitely pass undefined to next().
closes #2852