Skip to content

Commit cd59cc4

Browse files
committed
refactor(types): simplify placeholderData type definition by removing NonFunctionGuard
This simplification is possible due to the introduction of generic runtime utilities that handle value-or-function resolution. The new `resolveValueOrFunction()` utility handles the distinction between direct values and functions at runtime with proper type safety, eliminating the need for complex type-level guards.
1 parent 0d28e0a commit cd59cc4

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

packages/query-core/src/queryObserver.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import type { PendingThenable, Thenable } from './thenable'
1818
import type {
1919
DefaultError,
2020
DefaultedQueryObserverOptions,
21-
PlaceholderDataFunction,
2221
QueryKey,
2322
QueryObserverBaseResult,
2423
QueryObserverOptions,

packages/query-core/src/types.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ export type QueryFunctionContext<
162162

163163
export type InitialDataFunction<T> = () => T | undefined
164164

165-
type NonFunctionGuard<T> = T extends Function ? never : T
166-
167-
export type PlaceholderDataFunction<
165+
type PlaceholderDataFunction<
168166
TQueryFnData = unknown,
169167
TError = DefaultError,
170168
TQueryData = TQueryFnData,
@@ -420,13 +418,8 @@ export interface QueryObserverOptions<
420418
* If set, this value will be used as the placeholder data for this particular query observer while the query is still in the `loading` data and no initialData has been provided.
421419
*/
422420
placeholderData?:
423-
| NonFunctionGuard<TQueryData>
424-
| PlaceholderDataFunction<
425-
NonFunctionGuard<TQueryData>,
426-
TError,
427-
NonFunctionGuard<TQueryData>,
428-
TQueryKey
429-
>
421+
| TQueryData
422+
| PlaceholderDataFunction<TQueryData, TError, TQueryData, TQueryKey>
430423

431424
_optimisticResults?: 'optimistic' | 'isRestoring'
432425

0 commit comments

Comments
 (0)