Friday, 5 July 2019

Missing type annotation for a type parameter declared in function type that was implicitly instantiated at call of combineReducers

I am getting the following error on combineReducers in Redux now.

Missing type annotation for A. A is a type parameter declared in function type [1] and was implicitly instantiated at call of combineReducers [2].

The code looks as follows, but is ocurring in all of my reducers that use combineReducers.

export default combineReducers({
  status: ((state: boolean = true, action: Action) => {
    switch (action.type) {
      case 'START_SESSION':
      case 'REFRESH_AUTH_SUCCEEDED':
      case 'SIGN_IN_FAILED':
      case 'SIGN_OUT':
        return false;
      default:
        return state;
    }
  }: Reducer<*>),
});

I believe it is because of this type definition in the Redux flow-types


declare export function combineReducers<O: Object, A>(reducers: O): 
       CombinedReducer<$ObjMap<O, <S>(r: Reducer<S, any>) => S>, A>;


I believe this has to do with the release of Flow, version 0.85.0 which introduced some stuff having to do with "implicit instantiations."

I read this article on Medium by the FLow's own Sam Goldman and that is how I came to this conclusion. https://medium.com/flow-type/asking-for-required-annotations-64d4f9c1edf8

I was able to get the error to go away by doing the following which is my attempt at implementing something like the articles mention of the solution "providing explicit type argument to the function call."

export default combineReducers<Object, Action>({
  status: ((state: boolean = true, action: Action) => {
    switch (action.type) {
      case 'START_SESSION':
      case 'REFRESH_AUTH_SUCCEEDED':
      case 'SIGN_IN_FAILED':
      case 'SIGN_OUT':
        return false;
      default:
        return state;
    }
  }: Reducer<*>),
});

I did this because I saw that the function definition in the Redux docs was

combineReducers<O: Object, A>


But I do not fully understand why this works or know whether this is actually the right solution or makes no sense and I just got lucky. I have tried to search Google for IMPLICIT INSTANTIATIONS but I don't really find anything. I ready this article but I still dont know exactly what the return type of the call should be annotated as based on

combineReducers<O: Object, A>




from Missing type annotation for a type parameter declared in function type that was implicitly instantiated at call of combineReducers

No comments:

Post a Comment