0

I am missing something obvious, but I can't see it

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) is returning an array of Subject objects, but the compiler complains

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

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

What am I missing?

ed4becky
  • 1,488
  • 1
  • 17
  • 54

1 Answers1

1

Seems like you are confusing list and Observable map() function. This works for me assuming selectEntities returns the Ngrx Entity type Dictionary. The Parenthteses are hell though:

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

if 'subjects' is just a plain array, this will do:

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