diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 1e5a44f5..30a76b0f 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -44,13 +44,7 @@ export type WatchCallback = ( onInvalidate: InvalidateCbRegistrator ) => any -type MapSources = { - [K in keyof T]: T[K] extends WatchSource - ? V - : T[K] extends object ? T[K] : never -} - -type MapOldSources = { +type MapSources = { [K in keyof T]: T[K] extends WatchSource ? Immediate extends true ? (V | undefined) : V : T[K] extends object @@ -93,7 +87,7 @@ export function watch< Immediate extends Readonly = false >( sources: T, - cb: WatchCallback, MapOldSources>, + cb: WatchCallback, MapSources>, options?: WatchOptions ): WatchStopHandle @@ -115,10 +109,10 @@ export function watch< ): WatchStopHandle // implementation -export function watch( - source: WatchSource | WatchSource[], - cb: WatchCallback, - options?: WatchOptions +export function watch = false>( + source: T | WatchSource, + cb: any, + options?: WatchOptions ): WatchStopHandle { if (__DEV__ && !isFunction(cb)) { warn( @@ -127,11 +121,11 @@ export function watch( `supports \`watch(source, cb, options?) signature.` ) } - return doWatch(source, cb, options) + return doWatch(source as any, cb, options) } function doWatch( - source: WatchSource | WatchSource[] | WatchEffect, + source: WatchSource | WatchSource[] | WatchEffect | object, cb: WatchCallback | null, { immediate, deep, flush, onTrack, onTrigger }: WatchOptions = EMPTY_OBJ, instance = currentInstance @@ -262,11 +256,11 @@ function doWatch( } } - // important: mark the job as a watcher callback so that scheduler knows it + // important: mark the job as a watcher callback so that scheduler knows // it is allowed to self-trigger (#1727) job.allowRecurse = !!cb - let scheduler: (job: () => any) => void + let scheduler: ReactiveEffectOptions['scheduler'] if (flush === 'sync') { scheduler = job } else if (flush === 'post') { @@ -318,7 +312,7 @@ function doWatch( export function instanceWatch( this: ComponentInternalInstance, source: string | Function, - cb: Function, + cb: WatchCallback, options?: WatchOptions ): WatchStopHandle { const publicThis = this.proxy as any