Typescriot Redux cofigureStore method error

Viewed 50

I'm just after training and doing my first project by myself without any training materials help. I learned createStore method but since Redux says to use configureStore I wanted to use it this time. And I got that one error that I can't fix.

import { configureStore } from '@reduxjs/toolkit';
import { CartProductsSliceState } from '../interfaces/slices/cartProductsSlice.interface';
import { cartProductsSlice } from './cartRedux';

export const initialState: CartProductsSliceState =
  {
    cartProducts: [
      {
        id: '1',
        name: 'pizza',
        price: 12,
        amount: 1,
      },
    ],
  };

const store = configureStore({
  reducer: {
    cartProducts: cartProductsSlice.reducer,
  },
});

export default store;

the error says that: Type '{ id: string; name: string; price: number; amount: number; }' is not assignable to type 'ShoppingState'.

Here is a SliceState

import { ShoppingState } from '../../redux/mainTypes';

export interface CartProductsSliceState {
  cartProducts: ShoppingState[];
}

Interface:

export interface cartProduct {
  id: string;
  name: string;
  price: number;
  amount: number;
}

and finally ShoppingState, where cartState is cartProduct interface.

export interface ShoppingState {
  cartProducts: CartState;
}

I don't know what can cause this error, so some help would be appreciated. If these code parts are insufficient here is Github repository with it https://github.com/Devilish134/ts-pizzeria.

1 Answers

Problem solved. Had little time for long, but after got more found this small and stupid mistake I made. Instead

export interface CartProductsSliceState {
  cartProducts: ShoppingState[];
}

should be

export interface CartProductsSliceState {
  cartProducts: cartState;
}
Related