Skip to content

Select with a transform may break when refetchInterval is set to a function #5310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Nick-Lucas opened this issue Apr 22, 2023 · 3 comments
Closed
Labels
upstream wontfix This will not be worked on

Comments

@Nick-Lucas
Copy link
Contributor

Describe the bug

Writing code like this will produce a compiler error:

      useQuery({
        queryKey: ['my-query'],
        queryFn(ctx) {
          return { foo: 1 }
        },
        refetchInterval(data) {
          return 10000
        },
        select(data) {
          return data.foo
        },
      })

Removing data from refetchInterval makes it go away. This seems to be a conflict between the type change in select and the usage of data in callbacks.

Your minimal, reproducible example

#5309

Steps to reproduce

#5309

Expected behavior

This should work

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Everywhere

Tanstack Query adapter

react-query

TanStack Query version

4.29.4

TypeScript version

4.8.3-5.x

Additional context

No response

@Nick-Lucas
Copy link
Contributor Author

This was initially picked up in trpc/trpc#4234 but is actually a react-query issue as demonstrated by #5309

@Nick-Lucas
Copy link
Contributor Author

Looks like order in the object matters, this fixes the compile error:

      useQuery({
        queryKey: ['my-query'],
        queryFn(ctx) {
          return { foo: 1 }
        },
        select(data) {
          return data.foo
        },
        
        // move this below
        refetchInterval(data) {
          return 10000
        },
      })

Is most likely related to microsoft/TypeScript#53018

@TkDodo TkDodo closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2023
@TkDodo TkDodo added wontfix This will not be worked on upstream labels Apr 22, 2023
@TkDodo
Copy link
Collaborator

TkDodo commented Apr 22, 2023

if you want, please contribute a section to the docs on the typescript page that explains this limitation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants