Last active
November 15, 2018 12:05
-
-
Save gcanti/1e4494371c46f7f7ef4fb919778a32e9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
declare type Reducer<S, A> = (state: S, action: A) => S; | |
type ExtractState = <S>(r: Reducer<S, *>) => S; | |
declare function combineReducers<O, A>(reducers: O): Reducer<$ObjMap<O, ExtractState>, A>; | |
type State = { | |
name: string, | |
age: number | |
}; | |
type Action = any; | |
function reducerName(name: string, action: Action): string { | |
return name | |
} | |
function reducerAge(age: number, action: Action): number { | |
return age | |
} | |
// ok | |
const reducer0: Reducer<State, Action> = combineReducers({ | |
name: reducerName, | |
age: reducerAge | |
}) | |
// error | |
const reducer1: Reducer<State, Action> = combineReducers({ | |
name: reducerName | |
// missing age reducer | |
}) | |
// error | |
const reducer2: Reducer<State, Action> = combineReducers({ | |
name: reducerName, | |
age: reducerName // wrong reducer | |
}) | |
// error | |
const reducer3: Reducer<State, Action> = combineReducers({ | |
a: 1, // unknown key | |
name: reducerName, | |
age: reducerAge | |
}) | |
// error | |
const reducer4: Reducer<State, Action> = combineReducers({ | |
name: () => undefined, // bad reducer | |
age: reducerAge | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment