输入'Observable <void | =“”observable <void =“”>&gt;'不能分配给'Observable <action>'

时间:2018-06-12 11:17:49

标签: angular rxjs ngrx

我想了解effects

中的NgRX 6

我有一个示例效果:

  @Effect()
  createNonce$: Observable<Action> = this.actions$.pipe(
    ofType(INVALID_SESSION),
    map(() => generateNonce(32)),
    map(nonce => of(this.store.dispatch(new IdentityRedirect(nonce)))),
    catchError(error => of(console.error(error)))
  );

我想要实现的是

  1. 倾听INVALID_SESSION
  2. 致电generateNonce并返回结果
  3. 从上一张地图发送结果
  4. 我收到以下错误

    [ts]
    Type 'Observable<void | Observable<void>>' is not assignable to type 'Observable<Action>'.
      Type 'void | Observable<void>' is not assignable to type 'Action'.
        Type 'void' is not assignable to type 'Action'.
    

1 个答案:

答案 0 :(得分:0)

  @Effect()
  createNonce$: Observable<Action> = this.actions$.pipe(
    ofType(INVALID_SESSION),
    mergeMap(() =>
      of(generateNonce(32)).pipe(
        map(nonce => ({ type: REDIRECT_TO_LOGIN, payload: nonce }))
      )
    ),
    catchError(error => of({ type: REDIRECT_TO_LOGIN_FAILURE, payload: error }))
  );