Skip to content
Source
Sign inSign up
TanStack/query

Optimistic updates typescript example does not work locally #3314

Send to my agent
ClosedRowan-Paul(GitHub profile, opens in a new tab) opened this issue 2 comments

Describe the bug

Trying to run the optimistic updates typescript examples in the example folder on my local machine gives the following error: Argument of type 'UseQueryOptions<Todos, AxiosError<any>, TData, QueryKey> | undefined' is not assignable to parameter of type 'Omit<UseQueryOptions<Todos, AxiosError<any>, TData, "todos">, "queryKey" | "queryFn"> | undefined'.

Your minimal, reproducible example

The optimistic updates typescript example in the examples folder

Steps to reproduce

  1. Clone repository
  2. Run yarn in the examples\optimistic-updates-typescript folder
  3. Run yarn dev, open the browser

Expected behavior

The app runs like it does in the example in the docs

How often does this bug happen?

Every time

Screenshots or Videos

image

Platform

Windows 11 Home 21H2 Edge 98.0.1108.56 (Official build) (64-bit) Yarn v1.22.15 NPM 6.14.15 Node 14.18.2

react-query version

Commit eb4e863cf44d30ef8b936068fce09f9632def68a (latest at the moment)

TypeScript version

No response

Additional context

No response

  1. The example was built with react-query 3.5.1, which is why it works in codesandbox.

    for the latest version, the options need to omit queryKey and queryFn:

    function useTodos<TData = Todos>(
      options?: Omit<
        UseQueryOptions<Todos, AxiosError, TData>,
        "queryKey" | "queryFn"
      >
    ) {
      return useQuery("todos", fetchTodos, options);
    }

    I wouldn't make such an abstraction anymore, as it's pretty wide. I'll adapt the example for v4. The whole TodoCounter thing is unnecessary in v4 when tracked queries are the new default.

  2. TkDodo added labelsv4

  3. TkDodo added labelsdocumentation

  4. I fixed and simplified the example for v4: 61fd5397

  5. TkDodo closed this

Sign in to join this conversation.