query icon indicating copy to clipboard operation
query copied to clipboard

Optimistic updates typescript example does not work locally

Open Rowan-Paul opened this issue 4 years ago • 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

Rowan-Paul avatar Feb 19 '22 12:02 Rowan-Paul

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.

TkDodo avatar Feb 19 '22 14:02 TkDodo

I fixed and simplified the example for v4: 61fd5397

TkDodo avatar Feb 26 '22 16:02 TkDodo