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.
This commit is contained in:
Trevin Chow 2026-04-19 11:17:18 -07:00 committed by AgentSeal
parent 1af4d73da4
commit c0d24cc191
2 changed files with 3 additions and 3 deletions

View file

@ -15,7 +15,7 @@ import { parseDateRangeFlags } from './cli-date.js'
import { runOptimize, scanAndDetect } from './optimize.js'
import { renderCompare } from './compare.js'
import { getAllProviders } from './providers/index.js'
import { clearPlan, readConfig, readPlan, saveConfig, savePlan, getConfigFilePath } from './config.js'
import { clearPlan, readConfig, readPlan, saveConfig, savePlan, getConfigFilePath, type PlanId } from './config.js'
import { clampResetDay, getPlanUsageOrNull, type PlanUsage } from './plan-usage.js'
import { getPresetPlan, isPlanId, isPlanProvider, planDisplayName } from './plans.js'
import { createRequire } from 'node:module'
@ -95,7 +95,7 @@ function parseInteger(value: string): number {
}
type JsonPlanSummary = {
id: 'claude-pro' | 'claude-max' | 'cursor-pro' | 'custom'
id: PlanId
budget: number
spent: number
percentUsed: number

View file

@ -144,5 +144,5 @@ export async function getPlanUsageOrNull(today = new Date()): Promise<PlanUsage
}
export function isActivePlan(plan: Plan | undefined): plan is Plan {
return Boolean(plan) && plan.id !== 'none' && Number.isFinite(plan.monthlyUsd) && plan.monthlyUsd > 0
return plan !== undefined && plan.id !== 'none' && Number.isFinite(plan.monthlyUsd) && plan.monthlyUsd > 0
}