I'm trying to type a ts file which is for some slices in react js using redux. The problem is that I keep having this error : "Property 'quantity' does not exist on type 'never'.".
Here's the code :
addToCart: (state, action) => {
const itemInCart = state.cart.find(
(item: Record<string, unknown>) => item.id === action.payload.id
)
if (itemInCart) {
itemInCart.quantity++
} else {
state.cart.push({ ...action.payload, quantity: 1 })
}
},
I tried to add the Record<string, unknown> type but this doesn't make any changes. Do you have any suggestions ?