1

Have issues assigning an Observable<EnumValue[]> to Observable<EnumValue[]>.

fetchContactLocationStates()
{
   this.contactLocationStates$ = this.enumValues$
     .pipe(takeUntil(this.destroy$))
     .subscribe(x => x.filter((p) => p.CategoryId === EnumCategory.State));
}

Error:

Type 'Subscription' is missing the following properties from type 'Observable<EnumValue[]>' : source, operator, lift, subscribe, and 3 more.

enter image description here

Yong Shun
  • 35,286
  • 4
  • 24
  • 46
CorrieJanse
  • 2,374
  • 1
  • 6
  • 23

1 Answers1

2

contactLocationStates$ expects the value of Observable<EnumValue[]>. You shouldn't call the .subscribe().

import { map } from 'rxjs';

fetchContactLocationStates()
{
   this.contactLocationStates$ = this.enumValues$
     .pipe(
       takeUntil(this.destroy$),
       map((x) => x.filter((p) => p.CategoryId === EnumCategory.State))
     );
}
Yong Shun
  • 35,286
  • 4
  • 24
  • 46
  • 1
    It appears that `x` is of type Array, so I cannot use `x.CategoryId` – CorrieJanse Apr 11 '23 at 00:25
  • 1
    So `filter` is not a valid option. Not only because it returns an array but it Is also depreciated. however, I replaced filter with `map` and it works fine. Change your answer to map and I'll accept it. – CorrieJanse Apr 11 '23 at 00:30
  • Hi @CorrieJanse, apologies for the previous answer, and thanks for pointing it out. Ya, your propose changes are correct. – Yong Shun Apr 11 '23 at 01:02