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

huangapple go评论67阅读模式
英文:

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

问题

I'll provide a translation of the code and error message without any additional content:

在将Observable&lt;EnumValue[]&gt;分配给Observable&lt;EnumValue[]&gt;时出现问题。

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

错误:

类型 'Subscription' 缺少类型 'Observable<EnumValue[]>' 的以下属性:source、operator、lift、subscribe 等 3 个属性。

英文:

Have issues assigning an Observable&lt;EnumValue[]&gt; to Observable&lt;EnumValue[]&gt;.

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

Error:

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

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

答案1

得分: 2

contactLocationStates$ 期望值为 Observable&lt;EnumValue[]&gt;。 不应调用 .subscribe()

import { map } from &#39;rxjs&#39;;

fetchContactLocationStates()
{
   this.contactLocationStates$ = this.enumValues$
     .pipe(
       takeUntil(this.destroy$),
       map((x) =&gt; x.filter((p) =&gt; p.CategoryId === EnumCategory.State))
     );
}
英文:

contactLocationStates$ expects the value of Observable&lt;EnumValue[]&gt;. You shouldn't call the .subscribe().

import { map } from &#39;rxjs&#39;;

fetchContactLocationStates()
{
   this.contactLocationStates$ = this.enumValues$
     .pipe(
       takeUntil(this.destroy$),
       map((x) =&gt; x.filter((p) =&gt; p.CategoryId === EnumCategory.State))
     );
}

huangapple
  • 本文由 发表于 2023年4月11日 08:04:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75981558.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定