You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NgRx选择器返回初始状态,修复后遇类型匹配报错求助

NgRx新手问题:选择器返回空白初始状态而非API请求数据
  • 我是NgRx新手,当前遇到的问题是:选择器返回空白初始状态,而非Effects中API请求获取的数据。在home.component.ts中使用选择器时,得到如下输出:
homepage.component - global state - books is
["", {…}, 4, true, …]
0: ""
1: Object
2: 4
3: true
4: ""

homepage.component - global state - pokemon is
["", {…}, 4, true, …]
0: ""
1: Object
2: 4
3: true
4: ""
  • 确认Effects中的API调用正常,能获取到数据。
  • 已搭建可复现问题的示例,只需取消注释代码中“// Global State Calls Do Not Work”部分即可触发问题。

编辑补充:
我已修复选择器,并且处理了booksLoaded动作,但出现了新的类型错误:

No overload matches this call.
Overload 1 of 2, '(observerOrNext?: Partial | ((value: BooksState) => void) | undefined): Subscription', gave the following error.
Argument of type '(res: Book[]) => void' is not assignable to parameter of type 'Partial | ((value: BooksState) => void) | undefined'.

我怀疑book.reducer中Bookstate extends Book的写法没有达到预期效果...

内容的提问来源于stack exchange,提问作者Scottish Smile

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 15:02:37