import { EffectScope } from 'vue'; /** * 被装饰方法的类型约束: * - 方法体内应返回 void(装饰器会接管返回值) * - 但方法签名可以声明返回 EffectScope,以便调用侧获得正确的类型推断 * * 已知限制: * TypeScript 装饰器目前无法自动修改被装饰方法的返回类型。 * 原始方法返回 void,但装饰器在运行时将返回值替换为 EffectScope。 * 因此调用侧默认推断为 void,无法直接访问 EffectScope 的属性(如 stop())。 * * 方案 1(推荐):在调用侧强制类型转换 * 实际业务中通常只需要调用 stop() 方法来清理副作用,直接在调用侧做类型断言即可: * ```ts * const scope = reactiveDemo.setup() as any; * scope.stop(); * // 或者更精确的类型转换: * const scope = reactiveDemo.setup() as unknown as EffectScope; * scope.stop(); * ``` * * 方案 2:显式声明方法返回类型 + return 占位 * 在被装饰方法上声明返回 EffectScope,并在方法体末尾添加占位 return, * 这样调用侧可以直接获得正确的类型推断: * ```ts * import type { EffectScope } from 'vue'; * * class DemoService { * @RunInScope * public setup(): EffectScope { * watchEffect(() => { ... }); * return null as any; * // 或者:return null as unknown as EffectScope; * } * } * ``` */ type DecorableMethod = (this: any, ...args: any[]) => void | EffectScope; export declare function RunInScope(): (value: DecorableMethod, context: ClassMethodDecoratorContext) => (this: any, ...args: any[]) => EffectScope; export declare function RunInScope(value: DecorableMethod, context: ClassMethodDecoratorContext): (this: any, ...args: any[]) => EffectScope; export {};