From 77b3a27495c004267ab521b169ff41f23e3133a6 Mon Sep 17 00:00:00 2001 From: OpenSquared Date: Fri, 26 Jun 2026 14:50:07 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20TS2322=20in=20CalendarPage=20=E2=80=94?= =?UTF-8?q?=20typed=20bootstrap=20result=20vars=20outside=20JSX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Record index type prevents 'error' in narrowing, causing string | T to leak into ReactNode positions. Fix: precompute bootstrapError (string|null) and bootstrapEntries ([string, T][]) before JSX so TypeScript can resolve types correctly. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/pages/CalendarPage.tsx | 30 +++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/frontend/src/pages/CalendarPage.tsx b/frontend/src/pages/CalendarPage.tsx index 16ce0d2..1ec46db 100644 --- a/frontend/src/pages/CalendarPage.tsx +++ b/frontend/src/pages/CalendarPage.tsx @@ -41,9 +41,16 @@ interface SeriesMeta { assets: string[] } +interface BootstrapSeriesResult { + status: string + name?: string + inserted?: number + skipped?: number +} + interface BootstrapStatus { running: boolean - last_result: Record | { error: string } | null + last_result: unknown } // ── Constants ───────────────────────────────────────────────────────────────── @@ -152,8 +159,15 @@ function BootstrapPanel({ onDone }: { onDone: () => void }) { return () => clearInterval(iv) }, [polling]) - const result = bsStatus.last_result - const hasError = result && 'error' in result + const rawResult = bsStatus.last_result as Record | null + const bootstrapError: string | null = + rawResult && typeof (rawResult as { error?: unknown }).error === 'string' + ? (rawResult as { error: string }).error + : null + const bootstrapEntries: [string, BootstrapSeriesResult][] = + rawResult && !bootstrapError + ? (Object.entries(rawResult) as [string, BootstrapSeriesResult][]) + : [] return (
@@ -197,19 +211,19 @@ function BootstrapPanel({ onDone }: { onDone: () => void }) {
)} - {result && !bsStatus.running && ( - hasError ? ( -
Erreur : {'error' in result ? result.error : ''}
+ {rawResult && !bsStatus.running && ( + bootstrapError ? ( +
Erreur : {bootstrapError}
) : (
- {Object.entries(result as Record).map(([sid, r]) => ( + {bootstrapEntries.map(([sid, r]) => (
{sid}{' '} - {r.status === 'ok' ? `+${r.inserted} / skip ${r.skipped}` : 'failed'} + {r.status === 'ok' ? `+${r.inserted ?? 0} / skip ${r.skipped ?? 0}` : 'failed'}
))}