//Real Example============================
export type ProductType = {
_id: string;
pid: string;
name: string;
slug: string;
category: string;
image: string;
brand: string;
price: number;
countInStock: number;
rating: number;
reviews: number;
description: string;
};
export type State = {
products: ProductType[];
loading: boolean;
error: string;
};
export type Action =
| { type: 'FETCH_REQUEST' }
| { type: 'FETCH_SUCCESS'; payload: ProductType[] }
| { type: 'FETCH_FAIL'; payload: string };
export const initialState: State = {
products: [],
loading: true,
error: '',
};
//Cart Type ===========================
export type CartItemType = {
image: string | undefined;
slug: string;
quantity: number;
countInStock: number;
price: number;
_id: string;
pid: string;
name: string;
};
export type ShippingAddressType = {
fullname: string;
address: string;
city: string;
country: string;
pincode: string;
};
export type CartType = {
cartItems: CartItemType[];
shippingAddress: ShippingAddressType;
paymentMethod: string;
itemsPrice: number;
shippingCharges: number;
taxCharges: number;
totalPrice: number;
};
export type ActionType = | { type: 'SWITCH_MODE' } | { type: 'CART_ADD_ITEM'; payload: CartItemType };
export type AppStateType = { mode: string; cart: CartType; };