diff --git a/packages/reactivity/src/effect.ts b/packages/reactivity/src/effect.ts index a542e3b6..b4760088 100644 --- a/packages/reactivity/src/effect.ts +++ b/packages/reactivity/src/effect.ts @@ -2,11 +2,11 @@ import { OperationTypes } from './operations' import { Dep, targetMap } from './reactive' import { EMPTY_OBJ, extend } from '@vue/shared' -export interface ReactiveEffect { - (): any +export interface ReactiveEffect { + (): T isEffect: true active: boolean - raw: Function + raw: () => T deps: Array computed?: boolean scheduler?: (run: Function) => void @@ -35,10 +35,10 @@ export const activeReactiveEffectStack: ReactiveEffect[] = [] export const ITERATE_KEY = Symbol('iterate') -export function effect( - fn: Function, +export function effect( + fn: () => T, options: ReactiveEffectOptions = EMPTY_OBJ -): ReactiveEffect { +): ReactiveEffect { if ((fn as ReactiveEffect).isEffect) { fn = (fn as ReactiveEffect).raw } @@ -59,13 +59,13 @@ export function stop(effect: ReactiveEffect) { } } -function createReactiveEffect( - fn: Function, +function createReactiveEffect( + fn: () => T, options: ReactiveEffectOptions -): ReactiveEffect { - const effect = function effect(...args): any { +): ReactiveEffect { + const effect: ReactiveEffect = function effect(...args: any[]): any { return run(effect as ReactiveEffect, fn, args) - } as ReactiveEffect + } effect.isEffect = true effect.active = true effect.raw = fn diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 8a72d686..ebbe33c2 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -91,7 +91,7 @@ function doWatch( const instance = currentInstance const suspense = currentSuspense - let getter: Function + let getter: () => any if (isArray(source)) { getter = () => source.map(