From a623b70e4fae26c6d14ba9850c9de7583e9ce777 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Sat, 22 Mar 2025 11:37:06 +0000 Subject: [PATCH] Fix type error in useBudgetGoalUpdate The comparison `type === 'weekly'` was causing a type error because the type of `type` was `BudgetPeriod`, which includes `"monthly"` and `"weekly"`. The code was attempting to directly assign `"monthly"` to `type` after this comparison, which is not allowed. To fix this, a new variable `period` of type `BudgetPeriod` is created and assigned the value of `type`. The comparison is then performed on `period`, and if it is equal to `"weekly"`, `period` is set to `"monthly"`. Finally, `period` is used in the subsequent logic. --- src/contexts/budget/hooks/useBudgetGoalUpdate.ts | 9 +++++---- src/contexts/budget/hooks/useExtendedBudgetUpdate.ts | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/contexts/budget/hooks/useBudgetGoalUpdate.ts b/src/contexts/budget/hooks/useBudgetGoalUpdate.ts index c172f45..4ab6b4c 100644 --- a/src/contexts/budget/hooks/useBudgetGoalUpdate.ts +++ b/src/contexts/budget/hooks/useBudgetGoalUpdate.ts @@ -31,17 +31,18 @@ export const useBudgetGoalUpdate = ( return; } - // 주간 예산을 월간 예산과 동일하게 설정 + // 주간 예산을 월간 예산과 동일하게 설정하기 위한 타입 변환 + let updatedType: BudgetPeriod = type; if (type === 'weekly') { console.log(`주간 예산(${amount})을 월간 예산으로 직접 설정`); - type = 'monthly'; + updatedType = 'monthly'; } // 현재 최신 예산 데이터 로드 (다른 곳에서 변경되었을 수 있음) const currentBudgetData = safelyLoadBudgetData(); - // 예산 데이터 업데이트 - 입력된 타입 그대로 사용 - const updatedBudgetData = calculateUpdatedBudgetData(currentBudgetData, type, amount); + // 예산 데이터 업데이트 - 변환된 타입 사용 + const updatedBudgetData = calculateUpdatedBudgetData(currentBudgetData, updatedType, amount); console.log('새 예산 데이터 계산됨:', updatedBudgetData); // 상태 및 스토리지 둘 다 업데이트 diff --git a/src/contexts/budget/hooks/useExtendedBudgetUpdate.ts b/src/contexts/budget/hooks/useExtendedBudgetUpdate.ts index 3221344..011f2a9 100644 --- a/src/contexts/budget/hooks/useExtendedBudgetUpdate.ts +++ b/src/contexts/budget/hooks/useExtendedBudgetUpdate.ts @@ -17,15 +17,16 @@ export const useExtendedBudgetUpdate = ( ) => { console.log('확장 예산 업데이트 시작:', type, amount, newCategoryBudgets); - // 항상 주간 예산을 월간 예산과 동일하게 설정 + // 항상 주간 예산을 월간 예산과 동일하게 설정하기 위한 타입 변환 + let updatedType: BudgetPeriod = type; if (type === 'weekly') { console.log(`주간 예산(${amount})을 월간 예산으로 직접 사용`); - type = 'monthly'; + updatedType = 'monthly'; } // 예산 업데이트 - console.log(`예산 업데이트: 타입=${type}, 금액=${amount}`); - handleBudgetUpdate(type, amount); + console.log(`예산 업데이트: 타입=${updatedType}, 금액=${amount}`); + handleBudgetUpdate(updatedType, amount); // 카테고리 예산 업데이트 (제공된 경우) if (newCategoryBudgets) {