Skip to content

Commit c0d24cc

Browse files
tmchowiamtoruk
authored andcommitted
fix(plan): resolve type errors in plan summary and isActivePlan guard
Two pre-existing type errors surfaced during the rebase against main: 1. JsonPlanSummary.id was hardcoded to four plan ids, but PlanId now includes 'none' (PLAN_IDS was extended when 'codeburn plan clear' was added). toJsonPlanSummary only runs for active plans at runtime, but the static type still had to be widened. Use PlanId directly instead of the hand-rolled union. 2. isActivePlan used Boolean(plan) as the nullish guard, which doesn't narrow plan's type in TypeScript. Switch to an explicit 'plan !== undefined' so the subsequent .id and .monthlyUsd accesses type-check. npx tsc --noEmit is now clean; all 285 tests still pass.
1 parent 1af4d73 commit c0d24cc

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { parseDateRangeFlags } from './cli-date.js'
1515
import { runOptimize, scanAndDetect } from './optimize.js'
1616
import { renderCompare } from './compare.js'
1717
import { getAllProviders } from './providers/index.js'
18-
import { clearPlan, readConfig, readPlan, saveConfig, savePlan, getConfigFilePath } from './config.js'
18+
import { clearPlan, readConfig, readPlan, saveConfig, savePlan, getConfigFilePath, type PlanId } from './config.js'
1919
import { clampResetDay, getPlanUsageOrNull, type PlanUsage } from './plan-usage.js'
2020
import { getPresetPlan, isPlanId, isPlanProvider, planDisplayName } from './plans.js'
2121
import { createRequire } from 'node:module'
@@ -95,7 +95,7 @@ function parseInteger(value: string): number {
9595
}
9696

9797
type JsonPlanSummary = {
98-
id: 'claude-pro' | 'claude-max' | 'cursor-pro' | 'custom'
98+
id: PlanId
9999
budget: number
100100
spent: number
101101
percentUsed: number

src/plan-usage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,5 @@ export async function getPlanUsageOrNull(today = new Date()): Promise<PlanUsage
144144
}
145145

146146
export function isActivePlan(plan: Plan | undefined): plan is Plan {
147-
return Boolean(plan) && plan.id !== 'none' && Number.isFinite(plan.monthlyUsd) && plan.monthlyUsd > 0
147+
return plan !== undefined && plan.id !== 'none' && Number.isFinite(plan.monthlyUsd) && plan.monthlyUsd > 0
148148
}

0 commit comments

Comments
 (0)