Last active
March 5, 2019 00:55
-
-
Save treyhuffine/4712d1ea004dafa8e3c534fcd6078de2 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
type Dispatch<A> = (value: A) => void; | |
type Reducer<S, A> = (prevState: S, action: A) => S; | |
type ReducerState<R extends Reducer<any, any>> = R extends Reducer<infer S, any> ? S : never; | |
type ReducerAction<R extends Reducer<any, any>> = R extends Reducer<any, infer A> ? A : never; | |
function useReducer<R extends Reducer<any, any>, I>( | |
reducer: R, | |
initializerArg: I & ReducerState<R>, | |
initializer: (arg: I & ReducerState<R>) => ReducerState<R> | |
): [ReducerState<R>, Dispatch<ReducerAction<R>>]; | |
function useReducer<R extends Reducer<any, any>, I>( | |
reducer: R, | |
initializerArg: I, | |
initializer: (arg: I) => ReducerState<R> | |
): [ReducerState<R>, Dispatch<ReducerAction<R>>]; | |
function useReducer<R extends Reducer<any, any>>( | |
reducer: R, | |
initialState: ReducerState<R>, | |
initializer?: undefined | |
): [ReducerState<R>, Dispatch<ReducerAction<R>>]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment