`.next()` is available in observables returned by `.pipe()`
### Describe the bug
The following code shows a weird behavior of `.pipe()`:
```js
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
```typescript
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:
```js
const doubled$ = mySubj$.asObservable().pipe(
```
7 条评论