RdotSilva/TypeScript-MERN-Ecommerce

Typescript Error

Opened this issue · 0 comments

Types of property 'products' are incompatible.

I am just cloning your codebase. Your coding structure is awesome. But I get some errors. Please help me how can I fix it.

Example Error

error

Describe the bug #ts(2769)

(property) productList: Reducer<ProductListState, any>

No overload matches this call.
  Overload 1 of 3, '(reducers: ReducersMapObject<ReduxState, any>): Reducer<CombinedState<ReduxState>, AnyAction>', gave the following error.
    Type '(state: ProductListState | undefined, action: ProductListAction) => ProductListState | { loading: boolean; error?: undefined; products?: undefined; } | { loading: boolean; error: any; products: Product[]; }' is not assignable to type 'Reducer<ProductListState, any>'.
      Type 'ProductListState | { loading: boolean; error?: undefined; products?: undefined; } | { loading: boolean; error: any; products: Product[]; }' is not assignable to type 'ProductListState'.
        Type '{ loading: boolean; error?: undefined; products?: undefined; }' is not assignable to type 'ProductListState'.
          Types of property 'products' are incompatible.
            Type 'undefined' is not assignable to type 'Product[]'.ts(2769)
ReduxState.ts(28, 3): The expected type comes from property 'productList' which is declared here on type 'ReducersMapObject<ReduxState, any>'

Section code...

Get error from store.ts productList reducer

const reducer = combineReducers<ReduxState>({
  productList: productListReducer,
  productDetails: productDetailsReducer,
  cart: cartReducer,
  userLogin: userLoginReducer,
  userRegister: userRegisterReducer,
  userDetails: userDetailsReducer,
  userUpdateProfile: userUpdateProfileReducer,
  orderCreate: orderCreateReducer,
  orderDetails: orderDetailsReducer,
  orderPay: orderPayReducer,
  orderDeliver: orderDeliverReducer,
  orderListMy: orderListMyReducer,
  orderList: orderListReducer,
  userList: userListReducer,
  userDelete: userDeleteReducer,
  userUpdate: userUpdateReducer,
  productDelete: productDeleteReducer,
  productCreate: productCreateReducer,
  productUpdate: productUpdateReducer,
  productCreateReview: productCreateReducer,
  productTopRated: productTopRatedReducer,
});