【问题标题】:redux-observables + Typescript Uncaught TypeError: this.schedulerActionCtor is not a constructor, when running rootEpicredux-observables + Typescript Uncaught TypeError: this.schedulerActionCtor is not a constructor, when running rootEpic
【发布时间】:2021-08-31 10:00:09
【问题描述】:

我正在尝试通过一个示例项目来了解redux-observables 以及它如何与打字稿一起使用,并且我一直在关注一些指南herehere,但我一直遇到这个错误无论我如何设置史诗/中间件:

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


    【解决方案1】:

    将版本升级到redux-observable@2.0.0-rc.2 解决了这个问题(来自redux-observables repo 上的this 问题)。

    【讨论】:

      猜你喜欢
      • 2018-05-24
      • 1970-01-01
      • 2021-12-23
      • 1970-01-01
      • 2021-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-20
      相关资源
      最近更新 更多