I am trying to follow this example but am running into an issue when using combineLatest()
:
Property 'subscribe' does not exist on type 'OperatorFunction<unknown, [unknown, Item[], User[]]>'
Here is my facade:
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
import { combineLatest, distinctUntilChanged, map } from 'rxjs/operators';
export interface User {
test: string;
}
export interface Item {
test: string;
}
interface State {
items: Item[];
users: User[];
}
let _state: State = {
items: [],
users: [],
};
@Injectable()
export class Facade {
private store = new BehaviorSubject<State>(_state);
private state$ = this.store.asObservable();
items$ = this.state$.pipe(map(state => state.items), distinctUntilChanged());
emails$ = this.state$.pipe(map(state => state.users), distinctUntilChanged());
constructor(private http: HttpClient) {
combineLatest(this.items$, this.emails$).subscribe(
([items, users]) => {}
);
}
}
items$
and emails$
are both Observables. This code nearly mirrors the code in the example above, why am I getting this error?
Assuming you're using version 6+ of RxJS, as per the migration docs:
combineLatest
from rxjs/operators
has been deprecated. You should now import the method directly:
import { combineLatest } from 'rxjs';
The new version of combineLatest()
accepts an array of Observables
as its argument:
combineLatest([this.items$, this.emails$]).subscribe(([items, emails]) => {});
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