diff --git a/src/lib/api/mutations/job.mutations.ts b/src/lib/api/mutations/job.mutations.ts index 1b6cd7db..8784da54 100644 --- a/src/lib/api/mutations/job.mutations.ts +++ b/src/lib/api/mutations/job.mutations.ts @@ -129,9 +129,11 @@ export function useRemovePartyJobSkill() { const previousParty = queryClient.getQueryData(partyKeys.detail(shortcode)) // Optimistically remove the skill from the slot + // Convert slot number to string key to match jobSkills type (0-3) if (previousParty?.jobSkills) { const updatedSkills = { ...previousParty.jobSkills } - delete updatedSkills[slot] + const key = String(slot) as unknown as keyof typeof updatedSkills + delete updatedSkills[key] queryClient.setQueryData(partyKeys.detail(shortcode), { ...previousParty, jobSkills: updatedSkills diff --git a/src/lib/api/queries/party.queries.ts b/src/lib/api/queries/party.queries.ts index b8ae67a2..d1460ae1 100644 --- a/src/lib/api/queries/party.queries.ts +++ b/src/lib/api/queries/party.queries.ts @@ -21,8 +21,8 @@ export interface PartyPageResult { results: Party[] page: number totalPages: number - total: number - perPage: number + total?: number + perPage?: number } /** diff --git a/src/lib/query/ssr.ts b/src/lib/query/ssr.ts index 3ef7e822..008177cd 100644 --- a/src/lib/query/ssr.ts +++ b/src/lib/query/ssr.ts @@ -15,9 +15,10 @@ import type { QueryClient } from '@tanstack/svelte-query' */ export interface InitialDataOptions { /** - * The data fetched on the server to use as initial data + * The data fetched on the server to use as initial data. + * TanStack Query accepts TData | undefined but NOT null. */ - initialData: TData | undefined | null + initialData?: TData /** * Optional timestamp when the data was fetched on the server. @@ -33,6 +34,9 @@ export interface InitialDataOptions { * Use this helper when you have data fetched in a +page.server.ts load function * and want to use it as initial data for a TanStack Query. * + * Note: This helper strips `null` from the input since TanStack Query's + * initialData only accepts `TData | undefined`, not `null`. + * * @example * ```svelte * * ``` * - * @param initialData - The data fetched on the server + * @param initialData - The data fetched on the server (null is converted to undefined) * @param updatedAt - Optional timestamp when data was fetched (defaults to 0) * @returns Query options object with initialData and initialDataUpdatedAt */ export function withInitialData( initialData: TData | undefined | null, updatedAt?: number -): InitialDataOptions { +): InitialDataOptions> { return { - initialData: initialData ?? undefined, + initialData: (initialData ?? undefined) as NonNullable | undefined, initialDataUpdatedAt: updatedAt ?? 0 } }