Skip to content

Commit

Permalink
fix(types): make sure queryClient.setQueriesData can return undefined…
Browse files Browse the repository at this point in the history
… from the updater (#3657)
  • Loading branch information
TkDodo committed May 30, 2022
1 parent 4a43068 commit 0c04e7d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/core/queryClient.ts
Expand Up @@ -148,19 +148,19 @@ export class QueryClient {

setQueriesData<TData>(
queryKey: QueryKey,
updater: Updater<TData | undefined, TData>,
updater: Updater<TData | undefined, TData | undefined>,
options?: SetDataOptions
): [QueryKey, TData][]
): [QueryKey, TData | undefined][]

setQueriesData<TData>(
filters: QueryFilters,
updater: Updater<TData | undefined, TData>,
updater: Updater<TData | undefined, TData | undefined>,
options?: SetDataOptions
): [QueryKey, TData][]
): [QueryKey, TData | undefined][]

setQueriesData<TData>(
queryKeyOrFilters: QueryKey | QueryFilters,
updater: Updater<TData | undefined, TData>,
updater: Updater<TData | undefined, TData | undefined>,
options?: SetDataOptions
): [QueryKey, TData | undefined][] {
return notifyManager.batch(() =>
Expand Down
5 changes: 2 additions & 3 deletions src/core/tests/queryClient.test.tsx
Expand Up @@ -386,9 +386,8 @@ describe('queryClient', () => {
queryClient.setQueryData(['key', 1], 1)
queryClient.setQueryData(['key', 2], 2)

const result = queryClient.setQueriesData<number>(
['key'],
old => old! + 5
const result = queryClient.setQueriesData<number>(['key'], old =>
old ? old + 5 : undefined
)

expect(result).toEqual([
Expand Down

0 comments on commit 0c04e7d

Please sign in to comment.