const source2 = computed(() => source.value)
const source3 = () => 1
+type OnCleanup = (fn: () => void) => void
+
// lazy watcher will have consistent types for oldValue.
-watch(source, (value, oldValue) => {
+watch(source, (value, oldValue, onCleanup) => {
expectType<string>(value)
expectType<string>(oldValue)
+ expectType<OnCleanup>(onCleanup)
})
watch([source, source2, source3], (values, oldValues) => {
created() {
this.$watch(
() => this.a,
- (v, ov) => {
+ (v, ov, onCleanup) => {
expectType<number>(v)
expectType<number>(ov)
+ expectType<OnCleanup>(onCleanup)
},
)
},
: never
}
-type OnCleanup = (cleanupFn: () => void) => void
+export type OnCleanup = (cleanupFn: () => void) => void
export interface WatchOptionsBase extends DebuggerOptions {
flush?: 'pre' | 'post' | 'sync'
} from './component'
import { nextTick, queueJob } from './scheduler'
import {
+ type OnCleanup,
type WatchOptions,
type WatchStopHandle,
instanceWatch,
$watch<T extends string | ((...args: any) => any)>(
source: T,
cb: T extends (...args: any) => infer R
- ? (...args: [R, R]) => any
- : (...args: any) => any,
+ ? (...args: [R, R, OnCleanup]) => any
+ : (...args: [any, any, OnCleanup]) => any,
options?: WatchOptions,
): WatchStopHandle
} & IfAny<P, P, Omit<P, keyof ShallowUnwrapRef<B>>> &