Currently, I am delving into the @ngRx/store package within my Angular 14 App. My primary goal is to establish a basic store capable of containing a simple object Array. Here is an excerpt from my action file:
import { Product } from 'src/app/data-models/product-data-models';
import { ActionType } from "./../store.config";
export const loadProducts = createAction(ActionType.LOAD_PRODUCTS);
export const loadProductsSuccess = createAction(
ActionType.LOAD_PRODUCTS_SUCCESS,
props<{ payload: Product[] }>
);
export const loadProductsFailure = createAction(
ActionType.LOAD_PRODUCTS_FAILURE,
props<{ error: string }>
);
In addition, this is how my reducer file is structured:
import { createReducer, on } from '@ngrx/store';
import { Product } from 'src/app/data-models/product-data-models';
import { loadProducts, loadProductsSuccess, loadProductsFailure } from './product.action';
export interface ProductsState {
products: Product[];
error: string | null;
status: 'loading' | 'pending' | 'success' | 'error';
}
export const initialState: ProductsState = {
products: [],
error: null,
status: 'pending'
};
export const booksReducer = createReducer(
initialState,
on(loadProducts, (state) => ({
...state,
status: 'pending'
})),
on(loadProductsSuccess, (state, { payload }) => ({
...state,
products: payload,
error: null,
status: 'success'
})),
on(loadProductsSuccess, (state, { error }) => ({
...state,
error: error,
status: 'error'
}))
);
I have been grappling with an error in my reducer file:
Error: src/app/store/product-store/product.reducer.ts:25:37 - error TS2339: Property 'products' does not exist on type 'ActionCreatorProps<{ payload: Product[]; }> & TypedAction & { type: string; }'. 25 on(loadProductsSuccess, (state, { products }) => ({
Error: src/app/store/product-store/product.reducer.ts:31:37 - error TS2339: Property 'error' does not exist on type 'ActionCreatorProps<{ payload: Product[]; }> & TypedAction & { type: string; }'. 31 on(loadProductsSuccess, (state, { error }) => ({
Despite consulting various resources, including articles and examples, I remain unable to resolve this issue. If anyone could provide assistance, it would be greatly appreciated as I seem to be stuck without knowing where exactly I went wrong.