fix(mana/web/nutriphi): widen goal state types from literal to number

The DEFAULT_DAILY_VALUES constants are declared `as const` so each
field's type is a literal (e.g. `2000`, `50`). When the goals page
seeded its $state with these constants, TypeScript inferred the state
type as the literal — and any user-input number assignment then failed
type-check with "Type 'number' is not assignable to type '2000'".

The error was hidden until earlier today: the goals page also has the
same .current pre-existing pattern that the rest of the nutriphi
routes had, and tsc was short-circuiting on the .current error before
reaching the literal-type assignment. Now that queries.ts has been
moved to useLiveQueryWithDefault, .current is gone and the literal
typing surfaces.

Fix: explicitly type each $state as `<number>` so the literal widens
to a regular numeric state slot.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-04-09 18:12:13 +02:00
parent 3ef095aaff
commit 0426b6677b

View file

@ -5,13 +5,16 @@
import { ArrowLeft } from '@mana/shared-icons';
const allGoals = useAllGoals();
let currentGoals = $derived((allGoals.current ?? [])[0] ?? null);
let currentGoals = $derived(allGoals.value[0] ?? null);
let dailyCalories = $state(DEFAULT_DAILY_VALUES.calories);
let dailyProtein = $state(DEFAULT_DAILY_VALUES.protein);
let dailyCarbs = $state(DEFAULT_DAILY_VALUES.carbohydrates);
let dailyFat = $state(DEFAULT_DAILY_VALUES.fat);
let dailyFiber = $state(DEFAULT_DAILY_VALUES.fiber);
// DEFAULT_DAILY_VALUES is `as const`, so its fields are literal types
// (e.g. `2000`). Widen to plain `number` so the user can edit them
// without TS rejecting the assignment as a literal-type mismatch.
let dailyCalories = $state<number>(DEFAULT_DAILY_VALUES.calories);
let dailyProtein = $state<number>(DEFAULT_DAILY_VALUES.protein);
let dailyCarbs = $state<number>(DEFAULT_DAILY_VALUES.carbohydrates);
let dailyFat = $state<number>(DEFAULT_DAILY_VALUES.fat);
let dailyFiber = $state<number>(DEFAULT_DAILY_VALUES.fiber);
let saving = $state(false);
let saved = $state(false);