Skip to content
Source
Sign inSign up
TanStack/query

eslint-plugin: problems with optional chaining #8131

Send to my agent
ClosedTkDodo opened this issue 1 comment
TkDodocommented

When using optional chaining inside the queryFn, I get false positives reported by the linter:

This correctly yields no violations:

useQuery({
  queryKey: ['foo', options],
  queryFn: () => options.params ?? options
})

while this:

useQuery({
  queryKey: ['foo', options],
-  queryFn: () => options.params ?? options
+  queryFn: () => options?.params ?? options
})

falsely reports:

The following dependencies are missing in your queryKey: options?.params

Here’s a failing test case:

{
  name: 'should work with optional chaining',
  code: `useQuery({ queryKey: ['foo', options], queryFn: () => options?.params ?? options })`,
}

@Newbie012 FYI

  1. TkDodo added labelsbug

  2. TkDodo added labelspackage: eslint-plugin-query

  3. TkDodo closed this

Sign in to join this conversation.