These are the interfaces I have described:
enum ProductType {current, closed, coming}
export interface CurrentProductForCarousel {
type_product:ProductType.current;
offers: ProductMainInfo[]
}
export interface ProductMainInfo {
id: number;
disclaimer: string;
company?: {
registeredOfficeState?: string;
};
date: {
timestamp: number;
days: number;
hours: number;
};
}
I am using ngrx-store. Here is how my reducer looks like
export interface State {
currentProductForCarousel: CurrentProductForCarousel | null;
}
export const initialState: State = {
сurrentProductForCarousel: null,
};
export function reducer(state = initialState, action:
pruduct.Actions): State {
switch (action.type) {
case pruductActions.FETCH_PRODUCTS_CURRENT_SUCCESS: {
return {
...state,
currentProductsForCarousel: action.payload,
};
}
This is an example of response
{"success":true, "type_prudct":"current","products":[{"id":34, "disclaimer": "text", "company":{"registeredOfficeSuburb":"West Perth"}, "date":{"timestamp":1567987198,"days":710,"hours":"14"}}]}
The question now is how can I correctly set response data with the type of my interface to store and then retrieve data from the store?