From 0426b6677b6f87a0e4e750abeedf54d7d43f84a6 Mon Sep 17 00:00:00 2001 From: Till JS Date: Thu, 9 Apr 2026 18:12:13 +0200 Subject: [PATCH] fix(mana/web/nutriphi): widen goal state types from literal to number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 `` so the literal widens to a regular numeric state slot. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../src/routes/(app)/nutriphi/goals/+page.svelte | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/mana/apps/web/src/routes/(app)/nutriphi/goals/+page.svelte b/apps/mana/apps/web/src/routes/(app)/nutriphi/goals/+page.svelte index 2f05550c9..e4ad2b040 100644 --- a/apps/mana/apps/web/src/routes/(app)/nutriphi/goals/+page.svelte +++ b/apps/mana/apps/web/src/routes/(app)/nutriphi/goals/+page.svelte @@ -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(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); let saving = $state(false); let saved = $state(false);