Skip to content

Commit

Permalink
fix: any 타입 구체화
Browse files Browse the repository at this point in the history
  • Loading branch information
2yunseong committed May 25, 2023
1 parent 732c918 commit efe9759
Showing 1 changed file with 36 additions and 10 deletions.
46 changes: 36 additions & 10 deletions src/atoms/cartState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,43 @@ import {
} from '../api/api';
import type { CartType } from '../type/cart';

interface RequestAction {
action: string;
payload?: any;
}

export const cartRequestAction = atomFamily<RequestAction, any>({
key: 'cartRequestAction',
default: { action: 'GET', payload: {} },
});
type GetRequestAction = {
action: 'GET';
payload?: {};
};

type PostRequestAction = {
action: 'POST';
payload: {
productId: number;
quantity: number;
};
};

type PatchRequestAction = {
action: 'PATCH';
payload: { cartId: number; quantity: number };
};

type DeleteRequestAction = {
action: 'DELETE';
payload: { cartId: number };
};

type AllRequestAction =
| GetRequestAction
| PostRequestAction
| PatchRequestAction
| DeleteRequestAction;

export const cartRequestAction = atomFamily<AllRequestAction, AllRequestAction>(
{
key: 'cartRequestAction',
default: { action: 'GET', payload: {} },
}
);

export const cartState = selectorFamily<CartType[], any>({
export const cartState = selectorFamily<CartType[], AllRequestAction>({
key: 'cartQuery',
get:
(request) =>
Expand Down

0 comments on commit efe9759

Please sign in to comment.