diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index c1802e48183..13e5ab02774 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -54,26 +54,26 @@ type MapOldSources = { type InvalidateCbRegistrator = (cb: () => void) => void -export interface BaseWatchOptions { +export interface WatchOptionsBase { flush?: 'pre' | 'post' | 'sync' onTrack?: ReactiveEffectOptions['onTrack'] onTrigger?: ReactiveEffectOptions['onTrigger'] } -export interface WatchOptions extends BaseWatchOptions { +export interface WatchOptions extends WatchOptionsBase { immediate?: Immediate deep?: boolean } -export type StopHandle = () => void +export type WatchStopHandle = () => void const invoke = (fn: Function) => fn() // Simple effect. export function watchEffect( effect: WatchEffect, - options?: BaseWatchOptions -): StopHandle { + options?: WatchOptionsBase +): WatchStopHandle { return doWatch(effect, null, options) } @@ -85,7 +85,7 @@ export function watch = false>( source: WatchSource, cb: WatchCallback, options?: WatchOptions -): StopHandle +): WatchStopHandle // overload #2: array of multiple sources + cb // Readonly constraint helps the callback to correctly infer value types based @@ -98,14 +98,14 @@ export function watch< sources: T, cb: WatchCallback, MapOldSources>, options?: WatchOptions -): StopHandle +): WatchStopHandle // implementation export function watch( source: WatchSource | WatchSource[], cb: WatchCallback, options?: WatchOptions -): StopHandle { +): WatchStopHandle { if (__DEV__ && !isFunction(cb)) { warn( `\`watch(fn, options?)\` signature has been moved to a separate API. ` + @@ -120,7 +120,7 @@ function doWatch( source: WatchSource | WatchSource[] | WatchEffect, cb: WatchCallback | null, { immediate, deep, flush, onTrack, onTrigger }: WatchOptions = EMPTY_OBJ -): StopHandle { +): WatchStopHandle { if (__DEV__ && !cb) { if (immediate !== undefined) { warn( @@ -274,7 +274,7 @@ export function instanceWatch( source: string | Function, cb: Function, options?: WatchOptions -): StopHandle { +): WatchStopHandle { const publicThis = this.proxy as any const getter = isString(source) ? () => publicThis[source] diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 3c008c86c68..57812f34616 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -159,11 +159,11 @@ export { export { // types WatchEffect, - BaseWatchOptions, WatchOptions, + WatchOptionsBase, WatchCallback, WatchSource, - StopHandle + WatchStopHandle } from './apiWatch' export { InjectionKey } from './apiInject' export {