Search code examples
rxjsrxjs6

RxJS 6.5.5 startWith deprecated. Alternative


Update Angular to 9th version and occurred on startWith function stay deprecated. The documentation linked to AsyncScheduler class, but how to use it in my simple case I can't figure out:

private subscribeFilters(): void {
  this.filters.valueChanges
    .pipe(
      startWith(this.filters.value),
      pairwise(),
    )
    .subscribe(([prev, next]: [any, any]) => {
      if (JSON.stringify(prev) !== JSON.stringify(next)) {
        this.loadPage();
      }
    });
}

As you can see I'm using startWith for setting the filter initial state and exclude redundantly requests in the first time page load.

How I can implement the same logic without startWith. Perhaps as the documentation says with AsyncScheduler or another way?


Solution

  • I think this.filters or this.filters.value is any, that causes the issue because any matches SchedulerLike.

    Try to type them correctly, then it won't be detected as SchedulerLike anymore and the notice should be gone.