@@ -20,10 +20,14 @@ import { createEvents } from './utils/createEvents'
2020import { filterNoneValueObject , createParams , syncQuery2Conditions , isEquivalent , deepClone } from './utils/common'
2121import { containsProp , isNoData as isDataEmpty , isObject , isServer , rAF } from './utils/helper'
2222
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 {
2731 return containsProp (
2832 obj ,
2933 'fetcher' ,
@@ -50,7 +54,7 @@ export default function useConditionWatcher<O extends object, Result = unknown>(
5054 }
5155
5256 // default config
53- let watcherConfig : Config < O , Result > = {
57+ let watcherConfig : typeof config = {
5458 fetcher : config . fetcher ,
5559 conditions : config . conditions ,
5660 immediate : true ,
@@ -70,13 +74,13 @@ export default function useConditionWatcher<O extends object, Result = unknown>(
7074 const cache = useCache ( watcherConfig . fetcher , watcherConfig . cacheProvider ( ) )
7175
7276 const backupIntiConditions = deepClone ( watcherConfig . conditions )
73- const _conditions = reactive < O > ( watcherConfig . conditions )
77+ const _conditions = reactive < Cond > ( watcherConfig . conditions )
7478
7579 const isFetching = ref ( false )
7680 const isOnline = ref ( true )
7781 const isActive = ref ( true )
7882
79- const data : ShallowRef < Result > = shallowRef (
83+ const data : ShallowRef < any > = shallowRef (
8084 cache . cached ( backupIntiConditions ) ? cache . get ( backupIntiConditions ) : watcherConfig . initialData || undefined
8185 )
8286 const error = ref ( undefined )
@@ -110,9 +114,9 @@ export default function useConditionWatcher<O extends object, Result = unknown>(
110114 if ( isFetching . value ) return
111115 isFetching . value = true
112116 error . value = undefined
113- const conditions2Object : Conditions < O > = conditions
117+ const conditions2Object : Conditions < Cond > = conditions
114118 let customConditions : object = { }
115- const deepCopyCondition : Conditions < O > = deepClone ( conditions2Object )
119+ const deepCopyCondition : Conditions < Cond > = deepClone ( conditions2Object )
116120
117121 if ( typeof watcherConfig . beforeFetch === 'function' ) {
118122 let isCanceled = false
@@ -325,7 +329,7 @@ export default function useConditionWatcher<O extends object, Result = unknown>(
325329 } )
326330
327331 return {
328- conditions : _conditions as UnwrapNestedRefs < O > ,
332+ conditions : _conditions as UnwrapNestedRefs < Cond > ,
329333 data : readonly ( data ) ,
330334 error : readonly ( error ) ,
331335 isFetching : readonly ( isFetching ) ,
0 commit comments