@@ -860,9 +860,10 @@ declare namespace React {
860860 type Dispatch < A > = ( value : A ) => void ;
861861 // Since action _can_ be undefined, dispatch may be called without any parameters.
862862 type DispatchWithoutAction = ( ) => void ;
863- // Get the dispatch type from the reducer arguments
864- type ActionDispatch < ReducerRest extends any [ ] > =
865- ReducerRest extends [ any ] ? Dispatch < ReducerRest [ 0 ] > : DispatchWithoutAction ;
863+ // Limit the reducer to accept only 0 or 1 action arguments
864+ type AnyActionArg = [ ] | [ any ] ;
865+ // Get the dispatch type from the reducer arguments (captures optional action argument correctly)
866+ type ActionDispatch < ActionArg extends AnyActionArg > = ( ...args : ActionArg ) => void ;
866867 // Unlike redux, the actions _can_ be anything
867868 type Reducer < S , A > = ( prevState : S , action : A ) => S ;
868869 // If useReducer accepts a reducer without action, dispatch may be called without any parameters.
@@ -913,7 +914,7 @@ declare namespace React {
913914 * @version 16.8.0
914915 * @see https://reactjs.org/docs/hooks-reference.html#usereducer
915916 */
916- function useReducer < S , A extends any [ ] > (
917+ function useReducer < S , A extends AnyActionArg > (
917918 reducer : ( prevState : S , ...args : A ) => S ,
918919 initialState : S
919920 ) : [ S , ActionDispatch < A > ] ;
@@ -927,7 +928,7 @@ declare namespace React {
927928 * @version 16.8.0
928929 * @see https://reactjs.org/docs/hooks-reference.html#usereducer
929930 */
930- function useReducer < S , I , A extends any [ ] > (
931+ function useReducer < S , I , A extends AnyActionArg > (
931932 reducer : ( prevState : S , ...args : A ) => S ,
932933 initialArg : I ,
933934 init : ( i : I ) => S
0 commit comments