0

我的减速器有以下代码:

import { Reducer, combineReducers } from 'redux';
import { routerReducer } from 'react-router-redux';
import { firebaseReducer } from 'react-redux-firebase';
import { firestoreReducer } from 'redux-firestore';

const reducers: Reducer<ApplicationState> = combineReducers<ApplicationState>({
  firebase: firebaseReducer,
  firestore: firestoreReducer,
  router: routerReducer
});

export { reducers };

我非常关注可以在这里找到的教程

然而firestore,reducer 抱怨以下消息:

Argument of type '{ firebase: typeof firebaseReducer; firestore: typeof firestoreReducer; router: Reducer<RouterSta...' is not assignable to parameter of type 'ReducersMapObject'.
  Property 'firestore' is incompatible with index signature.
    Type 'typeof firestoreReducer' is not assignable to type 'Reducer<any>'.
      Type 'typeof firestoreReducer' provides no match for the signature '(state: any, action: AnyAction): any'.

可能是什么问题以及如何解决?

4

1 回答 1

1

似乎 TS 正在寻找一个Reducer在现场firebaseReducer,但发现了别的东西。为了看看那个“别的东西”是什么,我去看了类型,找到了这个,然后……很快就变得困惑了。看起来类型不仅仅是损坏了,它们甚至可能不存在。手动投射它可能是你最好的选择。

const reducers: Reducer<ApplicationState> = combineReducers<ApplicationState>({
  firebase: firebaseReducer,
  firestore: firestoreReducer as Reducer<ApplicationState>,
  router: routerReducer
});

我也会考虑为此打开一个问题或公关。这有点令人困惑,以前没有人遇到过这种情况。

于 2018-03-30T09:28:25.083 回答