From f8bb15e3768bd78b9d5703784f34c96e601faa80 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Sat, 28 Feb 2026 01:00:10 +0100 Subject: [PATCH] Fix typecheck 2 --- common/src/filters.ts | 50 +++++++++---------- common/src/util/array.ts | 16 ++++-- web/components/add-option-entry.tsx | 2 +- web/components/filters/last-active-filter.tsx | 2 +- .../filters/relationship-filter.tsx | 3 +- 5 files changed, 41 insertions(+), 32 deletions(-) diff --git a/common/src/filters.ts b/common/src/filters.ts index 0ac6629c..e2abfa0d 100644 --- a/common/src/filters.ts +++ b/common/src/filters.ts @@ -5,32 +5,32 @@ import {cloneDeep} from 'lodash' export type FilterFields = { orderBy: 'last_online_time' | 'created_time' | 'compatibility_score' - last_active: string | undefined - geodbCityIds: string[] | null - lat: number | null - lon: number | null - radius: number | null - raised_in_lat: number | null - raised_in_lon: number | null - raised_in_radius: number | null - genders: string[] - education_levels: string[] - mbti: string[] - name: string | undefined - shortBio: boolean | undefined - drinks_min: number | undefined - drinks_max: number | undefined + last_active: string | null | undefined + geodbCityIds: string[] | null | undefined + lat: number | null | undefined + lon: number | null | undefined + radius: number | null | undefined + raised_in_lat: number | null | undefined + raised_in_lon: number | null | undefined + raised_in_radius: number | null | undefined + genders: string[] | null | undefined + education_levels: string[] | null | undefined + mbti: string[] | null | undefined + name: string | null | undefined + shortBio: boolean | null | undefined + drinks_min: number | null | undefined + drinks_max: number | null | undefined // Big Five personality filters (0-100 range) - big5_openness_min: number | undefined - big5_openness_max: number | undefined - big5_conscientiousness_min: number | undefined - big5_conscientiousness_max: number | undefined - big5_extraversion_min: number | undefined - big5_extraversion_max: number | undefined - big5_agreeableness_min: number | undefined - big5_agreeableness_max: number | undefined - big5_neuroticism_min: number | undefined - big5_neuroticism_max: number | undefined + big5_openness_min: number | null | undefined + big5_openness_max: number | null | undefined + big5_conscientiousness_min: number | null | undefined + big5_conscientiousness_max: number | null | undefined + big5_extraversion_min: number | null | undefined + big5_extraversion_max: number | null | undefined + big5_agreeableness_min: number | null | undefined + big5_agreeableness_max: number | null | undefined + big5_neuroticism_min: number | null | undefined + big5_neuroticism_max: number | null | undefined } & { [K in OptionTableKey]: string[] } & Pick< diff --git a/common/src/util/array.ts b/common/src/util/array.ts index 50dc6c89..ae407e5f 100644 --- a/common/src/util/array.ts +++ b/common/src/util/array.ts @@ -32,10 +32,20 @@ export function groupConsecutive(xs: T[], key: (x: T) => U) { return result } -export function nullifyEmpty(array: T[]) { +export function undefineEmpty(array: T[]): T[] | undefined { + // Undefine a list if empty ([]) + return fallbackIfEmpty(array, undefined) +} + +export function nullifyEmpty(array: T[]): T[] | null { // Nullify a list if empty ([]) - if (!Array.isArray(array)) return null - return array.length > 0 ? array : null + return fallbackIfEmpty(array, null) +} + +export function fallbackIfEmpty(array: T[], fallback: any) { + // Fallback a list if empty ([]) + if (!Array.isArray(array)) return fallback + return array.length > 0 ? array : fallback } export function nullifyDictValues(array: Record) { diff --git a/web/components/add-option-entry.tsx b/web/components/add-option-entry.tsx index d00ff5e5..7b4c4196 100644 --- a/web/components/add-option-entry.tsx +++ b/web/components/add-option-entry.tsx @@ -26,7 +26,7 @@ export function AddOptionEntry(props: { String(s))} - onChange={(selected) => setProfile(label, selected)} + onChange={(selected) => setProfile(label, selected as string[] | undefined)} addOption={(v: string) => { console.log(`Adding ${label}:`, v) setChoices((prev: string[]) => ({...prev, [v]: v})) diff --git a/web/components/filters/last-active-filter.tsx b/web/components/filters/last-active-filter.tsx index 70185125..f2bda778 100644 --- a/web/components/filters/last-active-filter.tsx +++ b/web/components/filters/last-active-filter.tsx @@ -7,7 +7,7 @@ import {useT} from 'web/lib/locale' const DEFAULT_KEY = 'any' export function LastActiveFilterText(props: { - last_active: string | undefined + last_active: string | undefined | null highlightedClass?: string }) { const {last_active, highlightedClass} = props diff --git a/web/components/filters/relationship-filter.tsx b/web/components/filters/relationship-filter.tsx index cf984392..cdf5a31f 100644 --- a/web/components/filters/relationship-filter.tsx +++ b/web/components/filters/relationship-filter.tsx @@ -1,7 +1,6 @@ import clsx from 'clsx' import {RELATIONSHIP_CHOICES} from 'common/choices' import {FilterFields} from 'common/filters' -import {nullifyEmpty} from 'common/util/array' import {MultiCheckbox} from 'web/components/multi-checkbox' import {useT} from 'web/lib/locale' import {convertRelationshipType, RelationshipType} from 'web/lib/util/convert-types' @@ -60,7 +59,7 @@ export function RelationshipFilter(props: { choices={RELATIONSHIP_CHOICES as any} translationPrefix={'profile.relationship'} onChange={(c) => { - updateFilter({pref_relation_styles: nullifyEmpty(c)}) + updateFilter({pref_relation_styles: c}) }} /> )