Skip to content

Commit 92a0b66

Browse files
committed
docs(core): improve NonFunction type organization and documentation
Move NonFunction type definition above resolveOption function for better logical flow and add comprehensive JSDoc documentation explaining its purpose in preventing recursive type ambiguity in value-or-function patterns. - Add JSDoc for NonFunction type explaining constraint rationale - Move type definition before its usage for better code organization - Update resolveOption JSDoc to clarify T is constrained to non-function types - Improve code readability and developer understanding of type constraints
1 parent c64a5ea commit 92a0b66

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

packages/query-core/src/utils.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,30 @@ export function noop(): void
7878
export function noop(): undefined
7979
export function noop() {}
8080

81+
/**
82+
* Constraint type that excludes function types to prevent ambiguity in value-or-function patterns.
83+
*
84+
* This ensures that T in resolveOption<T> cannot be a function type itself, which would create
85+
* recursive ambiguity about whether to call the function or return it as the resolved value.
86+
*/
87+
type NonFunction =
88+
| string
89+
| number
90+
| boolean
91+
| bigint
92+
| symbol
93+
| null
94+
| undefined
95+
| object
96+
8197
/**
8298
* Resolves a value that can either be a direct value or a function that computes the value.
8399
*
84100
* This utility eliminates the need for repetitive `typeof value === 'function'` checks
85101
* throughout the codebase and provides a clean way to handle the common pattern where
86102
* options can be static values or dynamic functions.
87103
*
88-
* @template T - The type of the resolved value
104+
* @template T - The type of the resolved value (constrained to non-function types)
89105
* @template TArgs - Array of argument types when resolving function variants
90106
* @param value - Either a direct value of type T or a function that returns T
91107
* @param args - Arguments to pass to the function if value is a function
@@ -122,16 +138,6 @@ export function noop() {}
122138
* const delay = resolveOption(retryDelay, failureCount, error)
123139
* ```
124140
*/
125-
type NonFunction =
126-
| string
127-
| number
128-
| boolean
129-
| bigint
130-
| symbol
131-
| null
132-
| undefined
133-
| object
134-
135141
export function resolveOption<
136142
T extends NonFunction,
137143
TArgs extends Array<any>

0 commit comments

Comments
 (0)