0

I made this code:

return this.projectService.oneById(id).pipe(mergeMap(project => {
      if (!project) {
        return [];
      }

      const stories = this.getStories(id);

      return combineLatest(project.members.map(member => {
        return this.userService.one(member.id).pipe(map(memberData => {
          const assigned = stories.pipe(mergeMap(t => combineLatest(t.filter(task => {
            if (task && task.assignee?.id === member.id) {
              return {
                ...task,
                id: task.id
              };
            }
          }))));

          return {
            id: member.id,
            name: memberData?.displayName ?? 'Unknown',
            assigned
          };
        }));
      }));
    }));

But I'm having a problem because my function expects to return Observable<Type[]>, but it is currently returning Observable<{ ...etc, object: Observable<Type[]> }.

Obviously the problem is the observable inside the observable. I am, however, unsure how to fix this in this case. I have solved this many times in my current code, but this one is hard for me to understand because whatever I try nothing changes.

Thank you for helping in advance.

PS: the exact warning is this:

Type 'Observable<{ id: string; name: string; assigned: Observable<[UserStory | undefined]>; }[]>' is not assignable to type 'Observable<Member[]>'.   Type '{ id: string; name: string; assigned: Observable<[UserStory | undefined]>; }[]' is not assignable to type 'Member[]'.     Type '{ id: string; name: string; assigned: Observable<[UserStory | undefined]>; }' is not assignable to type 'Member'.       Types of property 'assigned' are incompatible.         Type 'Observable<[UserStory | undefined]>' is missing the following properties from type 'UserStory[]': length, pop, push, concat, and 25 more.
2
  • Can you provide your Member interface code? According the error your method returns data in other type than Member[]. Commented Jun 13, 2021 at 11:55
  • What is the shape of your Member type? You're returning an object of shape { id, name, assigned } as the output of your second map() which then leads to { id, name, assigned }[] as the output of your first map. If your Member type is something other than that shape and this.projectService.oneById returns Member[] then there will be issues. Commented Jun 13, 2021 at 11:57

1 Answer 1

1

threre is a place where you are trying to put an observable instead of array as an object fueld. This piece of code should be better

return this.projectService.oneById(id).pipe(mergeMap(project => {
  if (!project) {
    return [];
  }
  const stories = this.getStories(id);

  return combineLatest(project.members.map(member => {
    return this.userService.one(member.id).pipe(map(memberData => {
      const assigned$ = stories.pipe(mergeMap(t => combineLatest(t.filter(task => {
        if (task && task.assignee?.id === member.id) {
          return {
            ...task,
            id: task.id
          };
        }
      }))));
      return assigned$.pipe(map(assigned => ({
       id: member.id,
       name: memberData?.displayName ?? 'Unknown',
       assigned
      })));
    }));
  }));
}));
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.