From 39b2d7c9fdeb04e3d12fc664081a2469cc01c029 Mon Sep 17 00:00:00 2001 From: Yvv Date: Sat, 21 Feb 2026 15:28:00 +0100 Subject: [PATCH] Fix TypeScript errors in toPolyline function Accept undefined arrays and use non-null assertions for array indexing after length check. Co-Authored-By: Claude Opus 4.6 --- frontend/app/pages/commune/[slug]/index.vue | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/frontend/app/pages/commune/[slug]/index.vue b/frontend/app/pages/commune/[slug]/index.vue index 273211b..8644a67 100644 --- a/frontend/app/pages/commune/[slug]/index.vue +++ b/frontend/app/pages/commune/[slug]/index.vue @@ -529,16 +529,17 @@ const gridPrices2 = computed(() => { return arr }) -function toPolyline(vols: number[], vals: number[], cyFn: (v: number) => number) { - if (!vols?.length) return '' - // Downsample for performance (every 4th point) - return vols - .filter((_: number, i: number) => i % 4 === 0 || i === vols.length - 1) - .map((_: number, i: number) => { - const idx = i * 4 >= vols.length ? vols.length - 1 : i * 4 - return `${cx2(vols[idx])},${cyFn(vals[idx])}` - }) - .join(' ') +function toPolyline(vols: number[] | undefined, vals: number[] | undefined, cyFn: (v: number) => number): string { + if (!vols?.length || !vals?.length) return '' + const pts: string[] = [] + for (let i = 0; i < vols.length; i += 4) { + pts.push(`${cx2(vols[i]!)},${cyFn(vals[i]!)}`) + } + const last = vols.length - 1 + if (last % 4 !== 0) { + pts.push(`${cx2(vols[last]!)},${cyFn(vals[last]!)}`) + } + return pts.join(' ') } const baselineBillRP = computed(() => toPolyline(curveData.value?.baseline_volumes, curveData.value?.baseline_bills_rp, cy2bill))