From cac04c22ef143f4ae15c377a861655e5ef33f2a4 Mon Sep 17 00:00:00 2001 From: Arman Date: Fri, 9 Feb 2024 16:05:04 +0100 Subject: [PATCH] fix types? --- src/lib/components/filters/content.svelte | 44 ++++++++++++++--------- src/lib/components/filters/store.ts | 24 +++++++++---- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/lib/components/filters/content.svelte b/src/lib/components/filters/content.svelte index 86a6020b9..e7769c667 100644 --- a/src/lib/components/filters/content.svelte +++ b/src/lib/components/filters/content.svelte @@ -9,7 +9,7 @@ } from '$lib/elements/forms'; import { Query } from '@appwrite.io/console'; import { createEventDispatcher } from 'svelte'; - import { tags, type Operator, queries } from './store'; + import { tags, type Operator, queries, isTypeTagValue } from './store'; import type { Column } from '$lib/helpers/types'; import type { Writable } from 'svelte/store'; import { tooltip } from '$lib/actions/tooltip'; @@ -23,7 +23,7 @@ let columnId: string | null = null; $: column = $columns.find((c) => c.id === columnId) as Column; - let arrayValues = []; + let arrayValues: string[] = []; dispatch('apply', { applied: $tags.length }); @@ -213,20 +213,32 @@ diff --git a/src/lib/components/filters/store.ts b/src/lib/components/filters/store.ts index 13dc1f9b7..48c6ffe86 100644 --- a/src/lib/components/filters/store.ts +++ b/src/lib/components/filters/store.ts @@ -5,17 +5,27 @@ import { page } from '$app/stores'; import deepEqual from 'deep-equal'; import type { Column, ColumnType } from '$lib/helpers/types'; +type TagValue = { + tag: string; + value: string | number | string[]; +}; + +export function isTypeTagValue(obj: any): obj is TagValue { + return ( + obj && + typeof obj.tag === 'string' && + (typeof obj.value === 'string' || typeof obj.value === 'number') + ); +} + export type Operator = { - toTag: ( - attribute: string, - input?: string | number | string[] - ) => string | { tag: string; value: string }; + toTag: (attribute: string, input?: string | number | string[]) => string | TagValue; toQuery: (attribute: string, input?: string | number | string[]) => string; types: ColumnType[]; hideInput?: boolean; }; -export function mapToQueryParams(map: Map) { +export function mapToQueryParams(map: Map) { return encodeURIComponent(JSON.stringify(Array.from(map.entries()))); } @@ -25,7 +35,7 @@ export function queryParamToMap(queryParam: string) { return new Map(queries); } -function initQueries(initialValue = new Map()) { +function initQueries(initialValue = new Map()) { const queries = writable(initialValue); type AddFilterArgs = { @@ -41,7 +51,7 @@ function initQueries(initialValue = new Map { map.delete(tag); return map;