【问题标题】:Issue in NGX effects by passing payload to concatMapTo [actions]通过将有效负载传递给 concatMapTo [actions] 在 NGX 效果中出现问题
【发布时间】:2020-12-20 08:44:18
【问题描述】:

以下是我加载应用程序时用于触发某些操作的效果。当我运行下面的代码时,它会抛出错误。


@Injectable()
export class BootStrapEffects {
  bootStrap$ = createEffect(() => {
    return this.actions$.pipe(
      ofType(GetPrefSuccess),
      map((action) => action.payload),
      concatMapTo((payload: any) => [
        GetUser(payload.parsed.userId),
        GetMenu(payload.parsed.language),
      ])
    )
  })

  constructor(private actions$: Actions) {}
}

上面的代码抛出了下面的错误


error TypeError: You provided 'function (payload) { return [
                Object(_app_store_actions_account_action__WEBPACK_IMPORTED_MODULE_3__["GetUser"])(),
                Object(_app_store_actions_product_action__WEBPACK_IMPORTED_MODULE_7__["GetMenu"])()

  ]; }' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

来自 TSLint

Argument of type '() => Observable<never>' is not assignable to parameter of type '() => never'.
  Type 'Observable<never>' is not assignable to type 'never'.ts(2345)

谁能帮我解决这个错误?

【问题讨论】:

    标签: rxjs ngrx ngrx-effects rxjs-observables


    【解决方案1】:

    您可以尝试将concatMapTo 替换为concatMap concatMapTo 将 observable 作为参数,不关心上游返回什么,这意味着你不能使用上游的有效载荷。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-22
      • 1970-01-01
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-17
      相关资源
      最近更新 更多