rxjs
rxjs copied to clipboard
Multicasting and Reference Counting code examples in the docs don't typecheck
Describe the bug
The following code example is used on the Overview / Subject page under Multicasting and under Reference Counting:
import { from, Subject, multicast } from 'rxjs';
const source = from([1, 2, 3]);
const subject = new Subject();
const multicasted = source.pipe(multicast(subject));
// These are, under the hood, `subject.subscribe({...})`:
multicasted.subscribe({
next: v => console.log(`observerA: ${v}`),
});
multicasted.subscribe({
next: v => console.log(`observerB: ${v}`),
});
// This is, under the hood, `source.subscribe(subject)`:
multicasted.connect();
But if I paste that in a TypeScript file, I get this TypeScript error:
Property 'connect' does not exist on type 'Observable<unknown>'.ts(2339)
(The issue reported by TypeScript seems to because .pipe returns an Observable, not a Subject. I believe that that behaviour is undocumented. I only found out after hours of struggling: a more helpful answer on that issue and not blocking comments there would help a lot please).
I'm aware that multicast
has been deprecated. But refactoring using the migration guide does not solve the type error.
Expected behavior
The code example type checks.
Reproduction code
See above
Reproduction URL
No response
Version
7.5.6
Environment
No response
Additional context
No response