Skip to content

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

@afharo

Description

@afharo

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(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions