首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >redux-observables + Typescript未捕获TypeError:运行rootEpic时,redux不是构造函数

redux-observables + Typescript未捕获TypeError:运行rootEpic时,redux不是构造函数
EN

Stack Overflow用户
提问于 2021-06-15 22:23:32
回答 1查看 386关注 0票数 1

我正在尝试遵循一个示例项目来理解redux-observables以及它如何使用typescript,并且我一直在遵循一些指南herehere,但无论我如何设置epics/中间件,我都会遇到这个错误:

代码语言:javascript
复制
Uncaught TypeError: this.schedulerActionCtor is not a constructor
    at QueueScheduler.Scheduler.schedule (Scheduler.js?ef44:10)
    at eval (observeOn.js?142b:6)
    ...

在尝试设置中间件时,下面是我尝试运行的代码。

example/epics.ts:

代码语言:javascript
复制
import { delay, filter, mapTo } from 'rxjs/operators'
import { isOfType } from "typesafe-actions"

import { ExampleActionTypes } from './types'
import * as exampleActions from './actions'


export const pingEpic: Epic<RootAction, RootAction, RootState> = (action$) => action$.pipe(
  filter(isOfType(ExampleActionTypes.PING)),
  delay(1000), // Asynchronously wait 1000ms then continue
  mapTo(exampleActions.pong())
)

export const buttonEpic: Epic<RootAction, RootAction, RootState> = (action$) => action$.pipe(...)

export default {
  pingEpic, 
  buttonEpic
}

然后在rootEpic.ts中:

代码语言:javascript
复制
import { combineEpics } from 'redux-observable';
import {
  pingEpic,
  buttonEpic
} from './example/epics';


export default combineEpics(
  pingEpic,
  buttonEpic
)

在store.ts中:

代码语言:javascript
复制
...
export const epicMiddleware = createEpicMiddleware<RootAction, RootAction, RootState>()

const middlewares = [epicMiddleware]
const enhancer = composeEnhancers(applyMiddleware(...middlewares))

const store = createStore(
  rootReducer,
  initialState,
  enhancer
)

epicMiddleware.run(rootEpic)
...

来自package.json的库版本

代码语言:javascript
复制
    "redux": "4.1.0",
    "redux-observable": "1.2.0",
    "typesafe-actions": "5.1.0"

此外,如果我注释掉epicMiddleware.run(rootEpic)行,那么错误就会消失,但我真的不知道这说明了什么,除了我的epics或中间件有问题之外。我找不到我的类型不对齐的地方,或者是我在什么地方遗漏了一个步骤?

EN

回答 1

Stack Overflow用户

发布于 2021-06-18 15:30:48

将版本升级到redux-observable@2.0.0-rc.2修复了此问题(来自redux-observables存储库上的this问题)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67988157

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档