Skip to content

Commit 9d5931a

Browse files
committed
fix(queryClient): make sure that setQueryData can return undefined from the updater function on type level
the only runtime tests we had didn't use the previous value, so the generic defaults to unknown; the TS error becomes apparent when providing a generic to setQueryData
1 parent 0085137 commit 9d5931a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/core/queryClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export class QueryClient {
128128

129129
setQueryData<TData>(
130130
queryKey: QueryKey,
131-
updater: Updater<TData | undefined, TData> | undefined,
131+
updater: Updater<TData | undefined, TData | undefined>,
132132
options?: SetDataOptions
133133
): TData | undefined {
134134
const query = this.queryCache.find<TData>(queryKey)

src/core/tests/queryClient.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ describe('queryClient', () => {
311311

312312
test('should not update query data if updater returns undefined', () => {
313313
const key = queryKey()
314-
queryClient.setQueryData(key, 'qux')
315-
queryClient.setQueryData(key, () => undefined)
314+
queryClient.setQueryData<string>(key, 'qux')
315+
queryClient.setQueryData<string>(key, () => undefined)
316316
expect(queryClient.getQueryData(key)).toBe('qux')
317317
})
318318

0 commit comments

Comments
 (0)