Error with combineLatest after updating rxjs from 6.x to 7.x

333 Views Asked by At

After updating rxjs from version 6.6.6 to 7.4.0 I got an error in my combineLatest function.

searchQuery = new FormControl(null);
searchStatus = new FormControl<UserStatus>('ALL');

searchParams$ = combineLatest(
  this.searchQuery.valueChanges.pipe(startWith(null), debounceTime(200)),
  this.searchStatus.valueChanges.pipe(startWith('ALL')),
  (query: string, status: string) => {
    return { query, status };
  }
);

this is the error message

No overload matches this call. The last overload gave the following error. Argument of type '(query: string, status: string) => { query: string; status: string; }' is not assignable to parameter of type 'SchedulerLike'.

1

There are 1 best solutions below

0
Patrick On

The function signature of combineLatest has changed to:

export function combineLatest<A extends readonly unknown[]>(sources: readonly [...ObservableInputTuple<A>]): Observable<A>;

Your new code should look something like this:

searchParams$ = combineLatest([
    this.searchQuery.valueChanges.pipe(startWith(null), debounceTime(200)),
    this.searchStatus.valueChanges.pipe(startWith('ALL')),
])
    .pipe(
        map(([query, status]: [string | null, string | null]) => {
            return { query, status };
        }));