RxJs:映射到匿名类型对象

Jor*_*rdi 2 rxjs

我创建了这个Observable:

private accounts$: Observable<{type: string, alias: string}>;
Run Code Online (Sandbox Code Playgroud)

我需要将映射Array<Account>到{type, alias}对象流。到目前为止,我已经尝试过了:

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

但是我收到编译错误消息。

有任何想法吗?

Guy*_*Guy 5

您正在从箭头函数返回一个对象,但是括号建议函数主体。您需要()在返回的对象周围:

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