From 2c43ec1ad0a9fcab07930c974fda478d384d0abe Mon Sep 17 00:00:00 2001 From: Trevin Chow Date: Sun, 19 Apr 2026 11:17:18 -0700 Subject: [PATCH] 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. --- src/cli.ts | 4 ++-- src/plan-usage.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 71c55087..e23e24ef 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -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 diff --git a/src/plan-usage.ts b/src/plan-usage.ts index 8b9e16b5..78117343 100644 --- a/src/plan-usage.ts +++ b/src/plan-usage.ts @@ -144,5 +144,5 @@ export async function getPlanUsageOrNull(today = new Date()): Promise 0 + return plan !== undefined && plan.id !== 'none' && Number.isFinite(plan.monthlyUsd) && plan.monthlyUsd > 0 }