0

can I unsubscribe fromtEvent RxJs using takeUntil with Subject inside? My example code is like this:

private _closed$: Subject = new Subject<boolean>();
fromEvent(document, 'mousedown')
            .pipe(takeUntil(this._closed$));

But the problem is my linting shows me the error:

Argument of type 'Observable<unknown>' is not assignable to parameter of type 'OperatorFunction<Event, unknown>'.
  Type 'Observable<unknown>' provides no match for the signature '(source: Observable<Event>): Observable<unknown>'.ts(2345)

Thanks for your help.

2 Answers2

0

Subject type missing in declaration

private _closed$: Subject<boolean> = new Subject<boolean>();
fromEvent(document, 'mousedown')
            .pipe(takeUntil(this._closed$));
Iswarya
  • 1
  • 1
0

The subject can be of type void. Something like close$ = new Subject<void>() And then on OnDestroy() you can call close$.next(); and close$.complete() to trigger the notification for takeUntil()

Yozmo
  • 521
  • 2
  • 10