Skip to content

Commit

Permalink
refactor(components): improve types of getMinMaxTemporal
Browse files Browse the repository at this point in the history
If the input values are narrowed to a specific version of `Temporal`,
the result will also be typed to that specific version.
  • Loading branch information
fengelniederhammer committed Jul 19, 2024
1 parent 24d18d5 commit b07e0ac
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions components/src/query/queryRelativeGrowthAdvantage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ export async function queryRelativeGrowthAdvantage<LapisDateField extends string
mapNumerator.evaluate(lapis, signal),
mapDenominator.evaluate(lapis, signal),
]);
const { min, max } = getMinMaxTemporal(denominatorData.content.map((d) => 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<YearMonthDay, number>();
numeratorData.content.forEach((d) => {
Expand Down
6 changes: 3 additions & 3 deletions components/src/utils/temporal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,9 @@ export function compareTemporal(a: Temporal | null, b: Temporal | null): number
return 0;
}

export function getMinMaxTemporal(values: Iterable<Temporal | null>) {
let min = null;
let max = null;
export function getMinMaxTemporal<T extends Temporal>(values: Iterable<T | null>) {
let min: T | null = null;
let max: T | null = null;
for (const value of values) {
if (value === null) {
continue;
Expand Down

0 comments on commit b07e0ac

Please sign in to comment.