Skip to content
Source
Sign inSign up
TanStack/query

[bug] createQueries combine doesn't work #6151

Send to my agent
ClosedHugeLetters(GitHub profile, opens in a new tab) opened this issue 3 comments

Describe the bug

Here's a simple reproduction.

$: test = createQueries({
  queries: [
    {
      queryKey: [123],
      queryFn() {
        return 1;
      },
    },
    {
      queryKey: [234],
      queryFn() {
        return 2;
      },
    },
  ],
  combine(a) {
    return (a[0].data ?? 0) + (a[1].data ?? 0);
  },
});

Typescript reports that test is Readable<number> but it seems like combine doesn't get applied and the actual type is Readable<[QueryObserverResult<number>, QueryObserverResult<number>]> -

Your minimal, reproducible example

Steps to reproduce

Expected behavior

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Ubuntu 22.04

Tanstack Query adapter

svelte-query

TanStack Query version

5.0.0-beta.20

TypeScript version

5.2.2

Additional context

No response

  1. TkDodo closed this

  2. TkDodo added labelsinvalid

  3. A typescript playground shows that this is working as expected - I'm getting Readable<number> here: https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgYygUwIYzQRQK5pTBoDOcAvnAGZQQhwDkAAjBgHYmvIDWA9CQDc0AG2wBaAI4EoATwZxevODBlhSALjhRkAKB3IIHeFMLEyAXhTosuaWYAUCHXDgmiGuAG1nLxD9+u0jIA0mgymp4AjABMAMwAugA0-r5uMgBibPYAlH4BAegweFBscJEA3Cku5MkBNSlO+YGEIWERcQAsSVXNspk5eU1aaEUlcNGVTfV1tXDdLgYgAEbAbGj2GLmNvoXFpRueAAzxAHQAJlgYcAD813CHuQDUcAeRpxesN3cPkxTJ5NlKjo3GYdIo4AA9a5AA

    Yes, but the reported type doesn't correspond to the actual value. It's not actually a Readable<number>, it's Readable<[QueryObserverResult<number>, QueryObserverResult<number>]>. Here's a repro: https://stackblitz.com/edit/vitejs-vite-rkkqfg?file=src%2Flib%2FCounter.svelte You would expect to see result is 3 rendered. Instead you get image

    The bug is not that TS reports incorrect type(even though technically it is incorrect) but that combine doesn't actually do anything but the "reported" type makes it seem like it does.

  4. You're right, I thought it was just a typing issue, which is why I reproduced in typescript playground.

    @lachlancollins can you have a look at this please?

  5. TkDodo reopened this

  6. TkDodo removed labelsinvalid

  7. TkDodo added labelsbug

  8. TkDodo added labelsv5

  9. TkDodo added labelspackage: svelte-query

Sign in to join this conversation.