Repository: tannerlinsley/react-query
File: packages/react-query/src/__tests__/mutationOptions.test-d.tsx (TypeScript)

Code before:
    const isMutating = useIsMutating(mutationOpts)
    expectTypeOf(isMutating).toEqualTypeOf<number>()
  })

  it('should infer types when used with queryClient.isMutating', () => {
    const queryClient = new QueryClient()
    const mutationOpts = mutationOptions({
      mutationKey: ['key'],
      mutationFn: () => Promise.resolve(5),
    })

    const isMutating = queryClient.isMutating(mutationOpts)
    expectTypeOf(isMutating).toEqualTypeOf<number>()
  })

  it('should infer types when used with useMutationState', () => {
    const mutationOpts = mutationOptions({
      mutationKey: ['key'],
      mutationFn: () => Promise.resolve(5),
    })

    const mutationState = useMutationState({ filters: mutationOpts })
    expectTypeOf(mutationState).toEqualTypeOf<
      Array<MutationState<unknown, Error, unknown, unknown>>
    >()
  })
})


Review comment (suggestion):
<img width="741" alt="image" src="https://github.com/user-attachments/assets/191016fe-74d2-484c-8827-d167a9e40dc7" />

@TkDodo  When I read [this bsky comment](https://bsky.app/profile/tkdodo.eu/post/3lr3jww3t422t), 

<img width="603" alt="image" src="https://github.com/user-attachments/assets/6075f63c-2285-4ac5-abf1-69f9aa73e2eb" />

I thought below should make type error. but current implementation doesn't make type error

```suggestion
  it('should infer types when used with useMutationState', () => {
    const mutationState = useMutationState({
      filters: mutationOptions({
        mutationKey: ['key'],
        mutationFn: () => Promise.resolve(5),
      }),
    })
    expectTypeOf(mutationState).toEqualTypeOf<
      Array<MutationState<unknown, Error, unknown, unknown>>
    >()

    // @ts-expect-error this is a good error, because mutationOptions have no mutationKey
    useMutationState({
      filters: mutationOptions({ mutationFn: () => Promise.resolve(5) }),
    })
  })
```

<img width="1011" alt="image" src="https://github.com/user-attachments/assets/06cd9960-6762-4eb6-89ab-52b93f5fa966" />


Code after:
    >()

    useMutation(
      // should allow when used with useMutation without mutationKey
      mutationOptions({
        mutationFn: () => Promise.resolve('data'),
        onSuccess: (data) => {
          expectTypeOf(data).toEqualTypeOf<string>()
        },
      }),
    )
  })

  it('should infer types when used with useIsMutating', () => {
    const isMutating = useIsMutating(
      mutationOptions({
        mutationKey: ['key'],
        mutationFn: () => Promise.resolve(5),
      }),
    )
    expectTypeOf(isMutating).toEqualTypeOf<number>()

    useIsMutating(
      // @ts-expect-error filters should have mutationKey
      mutationOptions({
        mutationFn: () => Promise.resolve(5),
      }),
    )
  })

  it('should infer types when used with queryClient.isMutating', () => {
    const queryClient = new QueryClient()

    const isMutating = queryClient.isMutating(
      mutationOptions({
        mutationKey: ['key'],
        mutationFn: () => Promise.resolve(5),
      }),
    )
    expectTypeOf(isMutating).toEqualTypeOf<number>()

    queryClient.isMutating(
      // @ts-expect-error filters should have mutationKey
      mutationOptions({
        mutationFn: () => Promise.resolve(5),
      }),
    )
  })

  it('should infer types when used with useMutationState', () => {
    const mutationState = useMutationState({