Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RxJs: Map to anonymous type object

Tags:

rxjs

I've created this Observable:

private accounts$: Observable<{type: string, alias: string}>;

I need to map an Array<Account> to an stream of {type, alias} object. Up to now, I've tried this:

this.accounts$ = this.store$
  .select(fromRoot.getDBoxAccountEntities)
  .flatMap(accounts => accounts.map(account => {type: 'dbox', alias: account.dboxAccount}))
  ...

However I'm getting compilation error messages.

Any ideas?

like image 825
Jordi Avatar asked Jan 30 '23 17:01

Jordi


1 Answers

You are returning an object from your arrow function but the brackets suggest function body. You need () around your returned object:

.flatMap(accounts => accounts.map(account => ({type: 'dbox', alias: account.dboxAccount})))

like image 143
Guy Avatar answered Feb 16 '23 10:02

Guy