@@ -226,6 +226,39 @@ ruleTester.run('exhaustive-deps', rule, {
226
226
})
227
227
` ,
228
228
} ,
229
+ {
230
+ name : 'should pass with queryKeyFactory result assigned to a variable' ,
231
+ code : `
232
+ function fooQueryKeyFactory(dep: string) {
233
+ return ["foo", dep];
234
+ }
235
+
236
+ const useFoo = (dep: string) => {
237
+ const queryKey = fooQueryKeyFactory(dep);
238
+ return useQuery({
239
+ queryKey,
240
+ queryFn: () => Promise.resolve(dep),
241
+ })
242
+ }
243
+ ` ,
244
+ } ,
245
+ {
246
+ name : 'should pass with queryKeyFactory result assigned to a variable 2' ,
247
+ code : `
248
+ function fooQueryKeyFactory(dep: string) {
249
+ const x = ["foo", dep] as const;
250
+ return x as const;
251
+ }
252
+
253
+ const useFoo = (dep: string) => {
254
+ const queryKey = fooQueryKeyFactory(dep);
255
+ return useQuery({
256
+ queryKey,
257
+ queryFn: () => Promise.resolve(dep),
258
+ })
259
+ }
260
+ ` ,
261
+ } ,
229
262
{
230
263
name : 'should not treat new Error as missing dependency' ,
231
264
code : normalizeIndent `
@@ -246,6 +279,30 @@ ruleTester.run('exhaustive-deps', rule, {
246
279
}
247
280
` ,
248
281
} ,
282
+ {
283
+ name : 'should see id when there is a const assertion of a variable dereference' ,
284
+ code : normalizeIndent `
285
+ const useX = (id: number) => {
286
+ const queryKey = ['foo', id]
287
+ return useQuery({
288
+ queryKey: queryKey as const,
289
+ queryFn: async () => id,
290
+ })
291
+ }
292
+ ` ,
293
+ } ,
294
+ {
295
+ name : 'should see id when there is a const assertion assigned to a variable' ,
296
+ code : normalizeIndent `
297
+ const useX = (id: number) => {
298
+ const queryKey = ['foo', id] as const
299
+ return useQuery({
300
+ queryKey,
301
+ queryFn: async () => id,
302
+ })
303
+ }
304
+ ` ,
305
+ } ,
249
306
{
250
307
name : 'should not fail if queryKey is having the whole object while queryFn uses some props of it' ,
251
308
code : normalizeIndent `
0 commit comments