【发布时间】:2021-08-31 10:00:09
【问题描述】:
我正在尝试通过一个示例项目来了解redux-observables 以及它如何与打字稿一起使用,并且我一直在关注一些指南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, 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) 行,那么错误就会消失,但我真的不知道这告诉我什么,除了我的史诗或中间件有问题。我找不到我的类型没有对齐的地方,或者我在某处缺少某个步骤?
【问题讨论】:
标签: javascript typescript redux redux-observable