mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-08-19 13:34:41 +00:00
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:
parent
cb4c3ee305
commit
2c43ec1ad0
2 changed files with 3 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue