From dcd0a8b9e5e9abdc81f6f71710e2fdd6df9f821d Mon Sep 17 00:00:00 2001 From: Robert Carlson Date: Wed, 23 Aug 2023 20:10:38 -0700 Subject: [PATCH] Fix TypeScript error by adding type guard for 'min' and 'max' properties The TypeScript compiler was throwing errors because it couldn't find the properties 'min' and 'max' on the type 'BarReading'. The issue arises because TypeScript is unaware that 'min' and 'max' are only accessed when 'readings' is an array of 'LineReadings'. This commit adds a type guard to explicitly inform TypeScript about the type of 'reading', resolving the issue. --- src/client/app/utils/exportData.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client/app/utils/exportData.ts b/src/client/app/utils/exportData.ts index fde020263..9154cef48 100644 --- a/src/client/app/utils/exportData.ts +++ b/src/client/app/utils/exportData.ts @@ -39,9 +39,11 @@ function convertToCSV(readings: LineReading[] | BarReading[], meter: string, uni csvOutput += `${value},${startTimeStamp},${endTimeStamp}`; // Include min and max in export if appropriate." if (showMinMax) { - const min = reading.min * scaling; - const max = reading.max * scaling; - csvOutput += `,${min},${max}` + if ("min" in reading && "max" in reading) { + const min = reading.min * scaling; + const max = reading.max * scaling; + csvOutput += `,${min},${max}` + } } csvOutput += '\n'; });