Skip to content
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

.next() is available in observables returned by .pipe() #7543

Open
afharo opened this issue Apr 1, 2025 · 0 comments
Open

.next() is available in observables returned by .pipe() #7543

afharo opened this issue Apr 1, 2025 · 0 comments

Comments

@afharo
Copy link

afharo commented Apr 1, 2025

Describe the bug

The following code shows a weird behavior of .pipe():

const RxJs = require('rxjs');

const mySubj$ = new RxJs.Subject();

const doubled$ = mySubj$.pipe(
  RxJs.map((v) => v * 2),
);

mySubj$.subscribe((value) => {
  console.log('Original value:', value);
});

doubled$.subscribe((value) => {
  console.log('Doubled value:', value);
});

mySubj$.next(1); // Logs: 
// ✅ `Original value: 1`
// ✅ `Doubled value: 2`

doubled$.next(3); // Logs:
// ❌ `Original value: 3`
// ❌ `Doubled value: 6`

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 an Observable (where .next() is not available).

Reproduction code

const RxJs = require('rxjs');

const mySubj$ = new RxJs.Subject();

const doubled$ = mySubj$.pipe(
  RxJs.map((v) => v * 2),
);

mySubj$.subscribe((value) => {
  console.log('Original value:', value);
});

doubled$.subscribe((value) => {
  console.log('Doubled value:', value);
});

mySubj$.next(1); // Logs: 
// ✅ `Original value: 1`
// ✅ `Doubled value: 2`

doubled$.next(3); // Logs:
// ❌ `Original value: 3`
// ❌ `Doubled value: 6`

Reproduction URL

No response

Version

7.8.2

Environment

No response

Additional context

Currently, this is the workaround to achieve this:

const doubled$ = mySubj$.asObservable().pipe(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant