Skip to content

Commit

Permalink
Fix TypeScript error by adding type guard for 'min' and 'max' properties
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carlsonrob committed Aug 24, 2023
1 parent 5992b92 commit dcd0a8b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/client/app/utils/exportData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
});
Expand Down

0 comments on commit dcd0a8b

Please sign in to comment.