Skip to content
Source
Sign inSign up
TanStack/db

@tanstack/query-core interface pollution #1061

ClosedNick-Motion(GitHub profile, opens in a new tab) opened this issue 2 comments

When using Tanstack Query alongside DB, the extension of Register here affects all Query uses, leading to widespread type failures due to missing loadSubsetOptions:


error TS2741: Property 'loadSubsetOptions' is missing in type '{ ...: string; }' but required in type 'QueryCollectionMeta'.

138     meta: { source: '...' },
        ~~~~

  ../../node_modules/@tanstack/query-db-collection/dist/esm/global.d.ts:18:5 - 'loadSubsetOptions' is declared here.
    18     loadSubsetOptions: LoadSubsetOptions;

Extending the shared interface with a required DB-only field seems like the wrong solution.

  1. Hi @Nick-Motion,

    This is indeed an annoying problem. Unfortunately, i don't know of any other way to type tanstack Query's "meta" property. We basically based ourselves of this thread https://github.com/TanStack/query/discussions/2772. The problem with this is that it applies to all occurences. So either the Tanstack/db meta property will be wrong, or the non-ts/db related uses will be wrong. Really annoying!

    Tbh, i don't understand why Tanstack query is not parametric in the type of the Meta property, that would solve these problems.

  2. kevin-dp(GitHub profile, opens in a new tab) added labelshelp wanted

  3. Hi @Nick-Motion,

    Coming back to this. What about we make the loadSubsetOptions property optional in the typing of the meta property? In cases like yours where you are outside of the ts/db context the type checker wouldn't complain anymore and inside the ts/db context people would have to call the non-null assertion operator: meta.loadSubsetOptions!.

Sign in to join this conversation.