I have a contact service that is responsible for managing contacts, in a address book, type of way. for example my interface looks like this:
export interface AddressBook {
a?: Contact[];
//...
}
and Contact[]
is just stuff like name, age, email.
In my service I currently have this implementation:
private addressBook: Map<string, Contact[]> = new Map<string, Contact[]>();
private readonly ab$: BehaviorSubject<string | Contact[]> = new BehaviorSubject<string | Contact[]>(this.addressBook);
public constructor(){}
public getContacts(): Observable<string | Contact[]> {
return this.ab$.asObservable();
}
however the problem that I am getting is with the private readonly ab$: BehaviorSubject<string | Contact[]> = new BehaviorSubject<string | Contact[]>(this.addressBook)
where it says:
not assignable to parameter of type 'string | Contact[]'. Type 'Map' is missing the following properties from type 'Contact[]': length, pop, push, concat, and 21 more.ts(2345)
I cannot see where this error is coming from. Thank you guys for any help!
new BehaviorSubject(this.addressBook)
. You will trigger this expression has changed errors in Angular, and it is also an anti-pattern in functional programming. - Reactgularnew BehaviorSubject(this.addressBook)
- Ctfrancia