In my Angular project, I am developing a service with ngrx that is responsible for retrieving a list of messages from the store. Once it fetches the list, the service then needs to obtain additional asynchronous data for each message and create a new object called ModifiedMessage. The end goal is to have the service return an observable containing the list of modified messages.
Here is the code snippet I have written:
getMessages(): Observable<ModifiedMessage[]> {
return combineLatest(
this.store.select(MessageSelectors.getListOfMessages),
).pipe(
map(([messages]) => {
return messages.map(message => {
return this.store
.select(MessageSelectors.getUserForMessage(message.userId))
.pipe(
take(1),
map(user => {
return new ModifiedMessage({
id: message.id,
user: user.name,
});
})
);
});
})
);
}
I am facing an issue where TypeScript complains that I am returning Observable[]> instead of Observable[]. How can I resolve this problem?