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 <noreply@anthropic.com>
This commit is contained in:
Yvv
2026-02-21 15:28:00 +01:00
parent b30e54a8f7
commit 39b2d7c9fd

View File

@@ -529,16 +529,17 @@ const gridPrices2 = computed(() => {
return arr return arr
}) })
function toPolyline(vols: number[], vals: number[], cyFn: (v: number) => number) { function toPolyline(vols: number[] | undefined, vals: number[] | undefined, cyFn: (v: number) => number): string {
if (!vols?.length) return '' if (!vols?.length || !vals?.length) return ''
// Downsample for performance (every 4th point) const pts: string[] = []
return vols for (let i = 0; i < vols.length; i += 4) {
.filter((_: number, i: number) => i % 4 === 0 || i === vols.length - 1) pts.push(`${cx2(vols[i]!)},${cyFn(vals[i]!)}`)
.map((_: number, i: number) => { }
const idx = i * 4 >= vols.length ? vols.length - 1 : i * 4 const last = vols.length - 1
return `${cx2(vols[idx])},${cyFn(vals[idx])}` if (last % 4 !== 0) {
}) pts.push(`${cx2(vols[last]!)},${cyFn(vals[last]!)}`)
.join(' ') }
return pts.join(' ')
} }
const baselineBillRP = computed(() => toPolyline(curveData.value?.baseline_volumes, curveData.value?.baseline_bills_rp, cy2bill)) const baselineBillRP = computed(() => toPolyline(curveData.value?.baseline_volumes, curveData.value?.baseline_bills_rp, cy2bill))