如何解决通过将有效负载传递给concatMapTo [actions],NGX效果中的问题
以下是加载应用程序时用于触发某些操作的效果。当我运行以下代码时,它会引发错误。
@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作为参数,并不关心上游返回的内容,这意味着您不能使用上游的有效负载。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。