Redux combineReducer使用Flow和flow-typed for redux

时间:2017-07-24 13:20:43

标签: reactjs redux flowtype flow-typed

我在应用程序中加入了两个减速器,并结合了减速器(reducer.js)。

import { combineReducers } from 'redux';

export const reducers = {
    search: searchReducer,
    table: tableReducer
};

export const reducer = combineReducer(reducers);

此外,我还有一个片段可以使用来自流式类型redux_v3.x.x.js的存储来自动解析Reducer(来自this Medium post)的商店类型

import { reducers } from './reducer';

type Reducers = typeof reducers;

type $ExtractFunctionReturn = <V>(v: (...args: any) => V) => V;
export type State = $ObjMap<Reducers, $ExtractFunctionReturn>;

export type Store = ReduxStore<State, Actions>;

我从流式的CombinedReducer中得到一个错误,它无法找到reducer(搜索和表)。

src/types.js:65
65: export type Store = ReduxStore<State, Actions>;
                                ^^^^^ property `search`. Property not 
found in
54:   declare function combineReducers<O: Object, A>(reducers: O): 
CombinedReducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ object type. See lib: flow-
typed/npm/redux_v3.x.x.js:54

src/types.js:65
65: export type Store = ReduxStore<State, Actions>;
                                ^^^^^ property `table`. Property not 
found in
54:   declare function combineReducers<O: Object, A>(reducers: O): 
CombinedReducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ object type. See lib: flow-
typed/npm/redux_v3.x.x.js:54

如何解决该错误并使我的商店正常使用Flow?

在出现错误之前,我又得到了另一个

Flow: object map. This type is incompatible with union: Intersection 
type | undefined.
flow-typed/redux_v3.x.x.js
30: declare type CombinedReducer<S, A> = (state: $Shape<S> & {} | void

我已经添加了Object类型来声明类型CombinedReducer(实际上我不认为我应该编辑flow-typed,而在Medium示例中没有这样的错误):

declare type CombinedReducer<S, A> = (state: $Shape<S> & {} | Object | void

我认为这些错误可能是由同一件事造成的。

0 个答案:

没有答案