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.
This commit is contained in:
gpt-engineer-app[bot]
2025-03-22 11:37:06 +00:00
parent f1e0a9c297
commit a623b70e4f
2 changed files with 10 additions and 8 deletions

View File

@@ -31,17 +31,18 @@ export const useBudgetGoalUpdate = (
return; return;
} }
// 주간 예산을 월간 예산과 동일하게 설정 // 주간 예산을 월간 예산과 동일하게 설정하기 위한 타입 변환
let updatedType: BudgetPeriod = type;
if (type === 'weekly') { if (type === 'weekly') {
console.log(`주간 예산(${amount})을 월간 예산으로 직접 설정`); console.log(`주간 예산(${amount})을 월간 예산으로 직접 설정`);
type = 'monthly'; updatedType = 'monthly';
} }
// 현재 최신 예산 데이터 로드 (다른 곳에서 변경되었을 수 있음) // 현재 최신 예산 데이터 로드 (다른 곳에서 변경되었을 수 있음)
const currentBudgetData = safelyLoadBudgetData(); const currentBudgetData = safelyLoadBudgetData();
// 예산 데이터 업데이트 - 입력된 타입 그대로 사용 // 예산 데이터 업데이트 - 변환된 타입 사용
const updatedBudgetData = calculateUpdatedBudgetData(currentBudgetData, type, amount); const updatedBudgetData = calculateUpdatedBudgetData(currentBudgetData, updatedType, amount);
console.log('새 예산 데이터 계산됨:', updatedBudgetData); console.log('새 예산 데이터 계산됨:', updatedBudgetData);
// 상태 및 스토리지 둘 다 업데이트 // 상태 및 스토리지 둘 다 업데이트

View File

@@ -17,15 +17,16 @@ export const useExtendedBudgetUpdate = (
) => { ) => {
console.log('확장 예산 업데이트 시작:', type, amount, newCategoryBudgets); console.log('확장 예산 업데이트 시작:', type, amount, newCategoryBudgets);
// 항상 주간 예산을 월간 예산과 동일하게 설정 // 항상 주간 예산을 월간 예산과 동일하게 설정하기 위한 타입 변환
let updatedType: BudgetPeriod = type;
if (type === 'weekly') { if (type === 'weekly') {
console.log(`주간 예산(${amount})을 월간 예산으로 직접 사용`); console.log(`주간 예산(${amount})을 월간 예산으로 직접 사용`);
type = 'monthly'; updatedType = 'monthly';
} }
// 예산 업데이트 // 예산 업데이트
console.log(`예산 업데이트: 타입=${type}, 금액=${amount}`); console.log(`예산 업데이트: 타입=${updatedType}, 금액=${amount}`);
handleBudgetUpdate(type, amount); handleBudgetUpdate(updatedType, amount);
// 카테고리 예산 업데이트 (제공된 경우) // 카테고리 예산 업데이트 (제공된 경우)
if (newCategoryBudgets) { if (newCategoryBudgets) {