@@ -20,10 +20,14 @@ import { createEvents } from './utils/createEvents'
20
20
import { filterNoneValueObject , createParams , syncQuery2Conditions , isEquivalent , deepClone } from './utils/common'
21
21
import { containsProp , isNoData as isDataEmpty , isObject , isServer , rAF } from './utils/helper'
22
22
23
- export default function useConditionWatcher < O extends object , Result = unknown > (
24
- config : Config < O , Result >
25
- ) : UseConditionWatcherReturn < O , Result > {
26
- function isFetchConfig ( obj : object ) : obj is Config < O , Result > {
23
+ export default function useConditionWatcher <
24
+ Result extends unknown ,
25
+ Cond extends Record < string , any > ,
26
+ AfterResult extends unknown = Result
27
+ > (
28
+ config : Config < Result , Cond , AfterResult >
29
+ ) : UseConditionWatcherReturn < AfterResult extends Result ? Result : AfterResult , Cond > {
30
+ function isFetchConfig ( obj : object ) : obj is typeof config {
27
31
return containsProp (
28
32
obj ,
29
33
'fetcher' ,
@@ -50,7 +54,7 @@ export default function useConditionWatcher<O extends object, Result = unknown>(
50
54
}
51
55
52
56
// default config
53
- let watcherConfig : Config < O , Result > = {
57
+ let watcherConfig : typeof config = {
54
58
fetcher : config . fetcher ,
55
59
conditions : config . conditions ,
56
60
immediate : true ,
@@ -70,13 +74,13 @@ export default function useConditionWatcher<O extends object, Result = unknown>(
70
74
const cache = useCache ( watcherConfig . fetcher , watcherConfig . cacheProvider ( ) )
71
75
72
76
const backupIntiConditions = deepClone ( watcherConfig . conditions )
73
- const _conditions = reactive < O > ( watcherConfig . conditions )
77
+ const _conditions = reactive < Cond > ( watcherConfig . conditions )
74
78
75
79
const isFetching = ref ( false )
76
80
const isOnline = ref ( true )
77
81
const isActive = ref ( true )
78
82
79
- const data : ShallowRef < Result > = shallowRef (
83
+ const data : ShallowRef < any > = shallowRef (
80
84
cache . cached ( backupIntiConditions ) ? cache . get ( backupIntiConditions ) : watcherConfig . initialData || undefined
81
85
)
82
86
const error = ref ( undefined )
@@ -110,9 +114,9 @@ export default function useConditionWatcher<O extends object, Result = unknown>(
110
114
if ( isFetching . value ) return
111
115
isFetching . value = true
112
116
error . value = undefined
113
- const conditions2Object : Conditions < O > = conditions
117
+ const conditions2Object : Conditions < Cond > = conditions
114
118
let customConditions : object = { }
115
- const deepCopyCondition : Conditions < O > = deepClone ( conditions2Object )
119
+ const deepCopyCondition : Conditions < Cond > = deepClone ( conditions2Object )
116
120
117
121
if ( typeof watcherConfig . beforeFetch === 'function' ) {
118
122
let isCanceled = false
@@ -325,7 +329,7 @@ export default function useConditionWatcher<O extends object, Result = unknown>(
325
329
} )
326
330
327
331
return {
328
- conditions : _conditions as UnwrapNestedRefs < O > ,
332
+ conditions : _conditions as UnwrapNestedRefs < Cond > ,
329
333
data : readonly ( data ) ,
330
334
error : readonly ( error ) ,
331
335
isFetching : readonly ( isFetching ) ,
0 commit comments