ReactiveX / ReactiveX/rxjs

`.next()` is available in observables returned by `.pipe()`

Open
#7,543 7 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
31.7k
Forks
3k
PR merge metrics
No merged PRs in 30d

Description

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(

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing how Subject, asObservable(), and pipe() expose the returned observable at runtime, alongside the Observable and Subject types. Reproduce the example on version 7.8.2 and inspect existing tests for Subject and pipe behavior. Done means the piped observable no longer exposes or forwards .next(), while direct Subject usage and the documented asObservable() workaround remain consistent.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
api
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.