我正在尝试遵循一个示例项目来理解redux-observables以及它如何使用typescript,并且我一直在遵循一些指南here和here,但无论我如何设置epics/中间件,我都会遇到这个错误:
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:
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中:
import { combineEpics } from 'redux-observable';
import {
pingEpic,
buttonEpic
} from './example/epics';
export default combineEpics(
pingEpic,
buttonEpic
)在store.ts中:
...
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的库版本
"redux": "4.1.0",
"redux-observable": "1.2.0",
"typesafe-actions": "5.1.0"此外,如果我注释掉epicMiddleware.run(rootEpic)行,那么错误就会消失,但我真的不知道这说明了什么,除了我的epics或中间件有问题之外。我找不到我的类型不对齐的地方,或者是我在什么地方遗漏了一个步骤?
发布于 2021-06-18 15:30:48
将版本升级到redux-observable@2.0.0-rc.2修复了此问题(来自redux-observables存储库上的this问题)。
https://stackoverflow.com/questions/67988157
复制相似问题