Skip to content

Commit

Permalink
fix(types): adapt type definition of dataOrUpdater in setQueryData (#540
Browse files Browse the repository at this point in the history
)

since the updater receives `T | undefined`, it is difficult to construct a `T` from that. oldData can legitimately be `undefined`, but since `getQueryData` can also return `undefined` at any point, it makes more sense to have the updater be able to return `undefined` as well, which also means that `data` itself can be `undefined`
  • Loading branch information
TkDodo authored Jun 2, 2020
1 parent 3a589bb commit b528564
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ export interface CachedQuery<T, TError = unknown> {
config: QueryOptions<unknown, TError>
state: CachedQueryState<T>
setData(
dataOrUpdater: unknown | ((oldData: unknown | undefined) => unknown)
dataOrUpdater: unknown | undefined | ((oldData: unknown | undefined) => unknown | undefined)
): void
clear(): void
}
Expand Down Expand Up @@ -686,7 +686,7 @@ export interface QueryCache {
getQueryData<T = unknown>(key: AnyQueryKey | string): T | undefined
setQueryData<T = unknown>(
key: AnyQueryKey | string,
dataOrUpdater: T | ((oldData: T | undefined) => T)
dataOrUpdater: T | undefined | ((oldData: T | undefined) => T | undefined)
): void
refetchQueries<TResult>(
queryKeyOrPredicateFn:
Expand Down

0 comments on commit b528564

Please sign in to comment.