如何解决redux-observables + Typescript Uncaught TypeError: this.schedulerActionCtor 不是构造函数,当运行 rootEpic 时
我正在尝试按照一个示例项目来了解 redux-observables
以及它如何与 typescript 一起使用,并且我一直在遵循一些指南 here 和 here,但是无论我如何设置史诗/中间件,我都会遇到这个错误:
Uncaught TypeError: this.schedulerActionCtor is not a constructor
at QueueScheduler.Scheduler.schedule (Scheduler.js?ef44:10)
at eval (observeOn.js?142b:6)
...
在尝试设置中间件时,下面是我正在尝试使用的代码。
示例/epics.ts:
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,RootState> = (action$) => action$.pipe(...)
export default {
pingEpic,buttonEpic
}
然后在 rootEpic.ts 中:
import { combineEpics } from 'redux-observable';
import {
pingEpic,buttonEpic
} from './example/epics';
export default combineEpics(
pingEpic,buttonEpic
)
在 store.ts 中:
...
export const epicMiddleware = createEpicMiddleware<RootAction,RootState>()
const middlewares = [epicMiddleware]
const enhancer = composeEnhancers(applyMiddleware(...middlewares))
const store = createStore(
rootReducer,initialState,enhancer
)
epicMiddleware.run(rootEpic)
...
来自 package.json 的库版本
"redux": "4.1.0","redux-observable": "1.2.0","typesafe-actions": "5.1.0"
另外,如果我注释掉 epicMiddleware.run(rootEpic)
行,那么错误就会消失,但我真的不知道这告诉我什么,除了我的史诗或中间件有问题。我无法发现我的类型没有对齐的地方,或者我是否在某处遗漏了某个步骤?
解决方法
将版本升级到 redux-observable@2.0.0-rc.2
修复了该问题(来自 redux-observables
存储库上的 this 问题)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。