Replies: 6 comments
-
I can see the appeal of being able to do this, but until TypeScript supports something like the feature mentioned in this tweet, I don't think it's something we should do. And, even with such a feature, given the way that That's my two cents. |
Beta Was this translation helpful? Give feedback.
-
I would empathy for usefulness / demand of this, but my stand has not changed much : first, I don't see strong reason to introduce somewhat separate type variant from observable, secondly as Nicholas mentioned above I doubt this will play nice with all types we do constructed based on observable contract. And last, if those type issue's solvable I'd strongly suggest to start from userland instead of core library directly introduce it. |
Beta Was this translation helpful? Give feedback.
-
A better solution for this would be to have a different type entirely with a similar signature. This is something to think about and discuss, basically a Promise, only not eager and therefor overall more useful. Alternatively, we could have some operations that return a Promise or even a function that returns a Promise. All in all, though, this is pie-in-the-sky and there are a lot of other higher priority things to fix before we can address this, given that Observable, as a type, is fully capable of handling single values cleanly. |
Beta Was this translation helpful? Give feedback.
-
@benlesh as explained in the comments from you, @cartant and @kwonoj we won't implement this feature and therefore can close this issue. If not please explain why this issue should stay open. |
Beta Was this translation helpful? Give feedback.
-
It's not as helpful as a |
Beta Was this translation helpful? Give feedback.
-
Related to #2469 which contains more discussion |
Beta Was this translation helpful? Give feedback.
-
Feature Request
Is your feature request related to a problem? Please describe.
In many cases, an Observable will only ever emit a single value before completing (e.g. simple HTTP request), but there's no current way to encode that in the type system or to know what the lifetime of the subscription will be so as to properly clean up resources.
Describe the solution you'd like
A specialized type of Observable that only emits a single value - basically similar to RxJava's
Single
. The type would help communicate behavior, so that (for example) users subscribing to aSingle
Observable won't have to worry about unsubscribing. Ideally the type invariant would be preserved through operators, where appropriate.Describe alternatives you've considered
take(1)
, etc, to enforce at runtime. This leads to overly-defensive code that may usetake(1)
needlessly multiple times in a single pipeline.Other notes
This was brought up in #2469, along with Maybe and Completable, but was quickly closed without much discussion. Several people made good arguments for it, which I don't think were addressed, and I think there's a solid use case for something like this being in RxJS itself.
Beta Was this translation helpful? Give feedback.
All reactions