-
Notifications
You must be signed in to change notification settings - Fork 3k
.next()
is available in observables returned by .pipe()
#7543
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
Comments
Typescript types aren't exclusive. A property on a type means it exists, but the absence of a property does not mean that it doesn't. (This is how e.g. private properties work, they still exist on the type and could be accessed at runtime, but they make the typechecker unhappy). |
IMO, we shouldn't focus on the Typescript discussion. It was more of an additional point backing the bug report. Happy to remove it from the original description if it causes confusion. IMO, the bug is better explained by the lack of consistency in the APIs returned in
For consistency, In code example, the following behavior would be consistent, IMO doubled$.next(3);
// `Original value: 3` is not logged because we're emitting a new value from `doubled$`, not `mySubj$`.
// `Doubled value: 3` is logged because we're forcing `doubled$` to emit `3` (jumping the `.pipe()` since the API applies to the output of that `.pipe()`) |
@afharo I hear where you are coming from. It's confusing behaviour. On the other hand, the method you are calling is not part of the public API. The return type is Observable which does not expose a next() method. As soon as you call it, there is no defined "correct" behaviour. This is JS land, you can abuse the API in any number of ways. Mutate BehaviorSubject._value directly and it won't emit to its subscribers. But that's not a bug, you're just not using it according to the spec. |
@afharo I share in this sentiment. Here are my opinions;
|
Private properties are kinda bad performance wise if you have to downlevel them, which is what RxJS would do as it still publishes as es5/es2015. |
Describe the bug
The following code shows a weird behavior of
.pipe()
:There's an inconsistency in the APIs exposed by
doubled$
:.subscribe()
applies the observable returned by the.pipe()
.next()
applies to source of the.pipe()
(mySubj$
).Expected behavior
I would expect
.next()
to fail with not a function.According to the types,
.pipe()
returns anObservable
(where.next()
is not available).Reproduction code
Reproduction URL
No response
Version
7.8.2
Environment
No response
Additional context
Currently, this is the workaround to achieve this:
The text was updated successfully, but these errors were encountered: