Skip to content

Remove function overloads via codemod when the second argument is a function expression #6190

@balazsmatepetro

Description

@balazsmatepetro

Describe the bug

Currently, the following code snippet is not transformed by the remove-overloads codemod:

useQuery(ordersCacheKeys.groupOrders(ouuid), () =>
  api.getPatientGroupOrders(ouuid).then((r) => r.data)
)

After a quick sync with @TkDodo, it turned out in this case it's safe to do the transformation, because the second argument is a function expression, so it means the first parameter must be the query key. It means the code should be transformed into the following:

useQuery({
  queryKey: ordersCacheKeys.groupOrders(ouuid),
  queryFn: () => api.getPatientGroupOrders(ouuid).then((r) => r.data)
})

Here you can see the discussion: https://twitter.com/gothy/status/1714609270568698002

Your minimal, reproducible example


Steps to reproduce

Just run the codemod.

Expected behavior

It's mentioned in the 'Describe the bug' section.

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Doesn't matter.

Tanstack Query adapter

None

TanStack Query version

v5.0.0

TypeScript version

any

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions