Skip to content

TypeScript error accessing ctx.meta.loadSubsetOptions in queryFnΒ #802

@GraxMonzo

Description

@GraxMonzo

When accessing ctx.meta?.loadSubsetOptions inside a queryFn, an error occurs because meta is currently typed as Record<string, unknown> | undefined.

import { parseLoadSubsetOptions, queryCollectionOptions } from '@tanstack/query-db-collection';
import { createCollection } from '@tanstack/react-db';

export const imageTypesCollection = createCollection(
  queryCollectionOptions({
    queryClient,
    schema: imageTypeSchema,
    queryKey: ['image-types'],
    queryFn: (ctx) => {
// Argument of type 'unknown' is not assignable to parameter of type '{ where?: BasicExpression<boolean> | undefined; orderBy?: OrderBy | undefined; limit?: number | undefined; } | null | undefined'.ts
      const params = parseLoadSubsetOptions(ctx.meta?.loadSubsetOptions);

      return api.images.getAllTypes({ pageSize: 1_000_000 }, { signal: ctx.signal }).then((res) => res.data);
    },
    getKey: (item) => item.name,
    syncMode: 'on-demand',
  }),
);

@tanstack/query-db-collection v1.0.0
@tanstack/react-db v0.1.44
react v19.2
typescript v5.9.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions