通过将有效负载传递给 concatMapTo [actions] 在 NGX 效果中发布

Issue in NGX effects by passing payload to concatMapTo [actions]

下面是我加载应用程序时用来触发一些动作的效果。当我 运行 下面的代码抛出错误时。


@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)

谁能帮我解决这个错误?

您可以尝试将 concatMapTo 替换为 concatMap concatMapTo 以 observable 作为参数,不关心上游是什么returns,意思是你不能使用来自上游的 payload。