-
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
from is typed to accept any Subscribable, but only accepts Observables with Symbol.observable #4532
Comments
Hi there! I faced with the same problem and was surprised to see runtime error: RxJS typings definitely support I looked at the source code to understand what was the reason of rejecting my entity implementing Maybe me or someone will offer a solution by providing pull request? This feature will be very useful for me in some cases as I can replace my subscription helper with just Thank you. |
@bloadvenro go ahead :) |
I edited my post to add some argumentation about |
To reiterate, I agree with you and would encourage you to open a PR |
I'm facing the same issue trying to deserialize the // prop intentionally named as "subscribeLike" but not "subscribe"
// so you can't accidentally do "from(SubscribeLike)" like you can do using
// regular "Subscribable" and get runtime error due to the "Subscribable" inconsistency
export type SubscribeLike<T> = NoExtraProperties<{
subscribeLike: Subscribable<T>["subscribe"]
}>;
export function subscribableLikeToObservable<T>(
input: SubscribeLike<T>,
): Observable<T> {
return new Observable<T>((subscriber) => {
return input.subscribeLike(
(value) => subscriber.next(value),
(error) => subscriber.error(error),
() => subscriber.complete(),
);
})
} But would love |
@cartant I saw you commenting on #5066 (comment) and would love to discuss this more. Are you arguing in your comment towards improving the ergonomics of |
@felixfbecker see https://github.com/cartant/rxjs-interop/blob/master/README.md and the blog post linked therein. |
Thanks for the link, but that doesn't seem to help with the case of IPC/workers. Things would be a lot easier if instead of checking for |
@felixfbecker ATM, import { patch } from "rxjs-interop";
const foreignSource: Observable<Whatever> = /* some foreign source */;
foreignSource[Symbol.observable] = () => foreignSource;
patch(foreignSource);
// foreignSource will now be seen as an observable input by RxJS regardless of
// whether or not Symbol.observable was polyfilled by the application. Whether or not the API is relaxed regarding inputs having to implement |
Would the core team accept a PR to bring the implementation in line with the types? I.e. not throwing on |
It really depends upon the other issue upon which you commented: the |
I think the real resolution to this, short term, is to remove "Subscribable" from Long term: I think we should support |
…source in `from` and others. - Deprecates `SubscribableOrPromise` type and removes its usage throughout the library - Updates `ObservableInput` to be a more direct list and include `Observable` itself. - Updates `switchAll` to have proper typing (it broke after the refactor of `ObservableInput`), removing weird legacy type - Updates related tests Resolves ReactiveX#4532
…source in `from` and others. - Deprecates `SubscribableOrPromise` type and removes its usage throughout the library - Updates `ObservableInput` to be a more direct list and include `Observable` itself. - Updates `switchAll` to have proper typing (it broke after the refactor of `ObservableInput`), removing weird legacy type - Updates related tests Resolves ReactiveX#4532
#1980 was closed so opening a new one.
Currently
from()
is typed to accept any object with a subscribe method. But at runtime it actually throws if the object does not have aSymbol.observable
property. The types or implementation should be corrected.Personally I prefer using
Subscribable
becauseSymbol.observable
is not even standard and it is a global property. There can be nasty bugs if polyfills are loaded wrong (e.g. Rx is loaded first, then something importssymbol-observable
which will mutate the globalSymbol.observable
and then make Rx's symbol checks fail because it already set it to"@@observable"
or the Observable was created before (I've already lost hours debugging real bugs caused from this).The text was updated successfully, but these errors were encountered: