From b07e0ac3501896ce18e1f96fc9442fdf359f1b12 Mon Sep 17 00:00:00 2001 From: Fabian Engelniederhammer Date: Fri, 19 Jul 2024 12:01:23 +0200 Subject: [PATCH] refactor(components): improve types of `getMinMaxTemporal` If the input values are narrowed to a specific version of `Temporal`, the result will also be typed to that specific version. --- components/src/query/queryRelativeGrowthAdvantage.ts | 6 ++---- components/src/utils/temporal.ts | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/components/src/query/queryRelativeGrowthAdvantage.ts b/components/src/query/queryRelativeGrowthAdvantage.ts index f93623a6..558fcadb 100644 --- a/components/src/query/queryRelativeGrowthAdvantage.ts +++ b/components/src/query/queryRelativeGrowthAdvantage.ts @@ -28,12 +28,10 @@ export async function queryRelativeGrowthAdvantage d.date)); - if (!min && !max) { + const { min: minDate, max: maxDate } = getMinMaxTemporal(denominatorData.content.map((d) => d.date)); + if (!minDate && !maxDate) { return null; } - const minDate = min as YearMonthDay; - const maxDate = max as YearMonthDay; const numeratorCounts = new Map(); numeratorData.content.forEach((d) => { diff --git a/components/src/utils/temporal.ts b/components/src/utils/temporal.ts index b920bdb5..0810fee4 100644 --- a/components/src/utils/temporal.ts +++ b/components/src/utils/temporal.ts @@ -345,9 +345,9 @@ export function compareTemporal(a: Temporal | null, b: Temporal | null): number return 0; } -export function getMinMaxTemporal(values: Iterable) { - let min = null; - let max = null; +export function getMinMaxTemporal(values: Iterable) { + let min: T | null = null; + let max: T | null = null; for (const value of values) { if (value === null) { continue;