地图函数不接受 'Subjects' 的流

map function not accepting stream of 'Subjects'

我遗漏了一些明显的东西,但我看不到它

export const subjectSelector: MemoizedSelector<
  any,
  Subject[]
> = new EntitySelectorsFactory().create<Subject>('subject').selectEntities;
    this.store.pipe(
      select(entitySelectors.subjectSelector),
      map((s:Subject) => return {...s, z: {}}),
      filter((subject:Subject) => subject.z.evidence && subject.z.evidence.length > 0)

    );

select(entitySelectors.subjectSelector) 正在返回 Subject 对象数组,但编译器抱怨

  Type 'Subject' is missing the following properties from type 'Subject[]': length, pop, push, concat, and 28 more.

map((s:Subject) => return {...s, z: {}}),

我错过了什么?

您似乎混淆了 list 和 Observable map() 函数。假设 selectEntities returns Ngrx 实体类型字典,这对我有用。括号是地狱:

this.store.pipe(select(subjectSelector),
    map((subjects: Dictionary<Subject>) => Object.values(subjects).map(s => ({...s, z: {}}))));

如果 'subjects' 只是一个普通数组,这样就可以:

this.store.pipe(select(subjectSelector),
    map((subjects: Subject[]) => subjects.map(s => ({...s, z: {}}))));