I've noticed recently after upgrading my rxjs version that you can't use the .next() method this.ngUnsubscribe$.next(); as it is anymore as you would below:
export class TakeUntilComponent implements OnDestroy {
// Our magical observable that will be passed to takeUntil()
private readonly ngUnsubscribe$: Subject<void> = new Subject<void>();
// Our subject that we will subscribe to
subjectA$: Subject<number> = new Subject<number>();
constructor() {
this.subjectA$
.pipe(takeUntil(this.ngUnsubscribe$))
.subscribe(value => {
// logic goes here ...
});
}
ngOnDestroy(){
// Emit a value so that takeUntil will handle the closing of our subscriptions;
this.ngUnsubscribe$.next();
// Unsubscribe from our unsubscriber to avoid creating a memory leak
this.ngUnsubscribe$.unsubscribe();
}
}
But now you must send an argument to it like this:
this.ngUnsubscribe$.next(null);
or
this.ngUnsubscribe$.next(true);
My question is why? And what value would you know to send?
This happens after upgrading rxjs version to 7 from 6
Rxjs 7 changes
After checking the changelog and several github issues about this situation,
Subject: resolve issue where Subject constructor errantly allowed an argument (#5476) (e1d35dc)
Subject: no default generic (e678e81)
Changelog 7.0.0-beta.1 and the commit where empty value is removed from the tests

I realized that the solution was to either provide a value or simply typecast the Subject with <void> (as @martin also said) as in destroy$ = new Subject<void>() if you want to next it with an empty value.
My related post: rxjs 7 update - Subject - Expected 1 arguments, but got 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With