From 3e410bc085c7bba402caa6b6e1d8bc20d4aaf25c Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Sun, 1 Aug 2021 11:40:50 +0800 Subject: [PATCH 1/2] fix(types): fix `this` type broken in computed options --- packages/reactivity/src/computed.ts | 2 +- test-dts/defineComponent.test-d.tsx | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/reactivity/src/computed.ts b/packages/reactivity/src/computed.ts index 4c984d3d65a..d5eb6285191 100644 --- a/packages/reactivity/src/computed.ts +++ b/packages/reactivity/src/computed.ts @@ -12,7 +12,7 @@ export interface WritableComputedRef extends Ref { readonly effect: ReactiveEffect } -export type ComputedGetter = (ctx?: any) => T +export type ComputedGetter = (...ctx: any) => T export type ComputedSetter = (v: T) => void export interface WritableComputedOptions { diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index dba11f20b9b..b28bbed6b4a 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -396,12 +396,12 @@ describe('type inference w/ options API', () => { } }, computed: { - d(): number { + d() { expectType(this.b) return this.b + 1 }, e: { - get(): number { + get() { expectType(this.b) expectType(this.d) @@ -514,10 +514,10 @@ describe('with mixins', () => { expectType(props.aP1) }, computed: { - dC1(): number { + dC1() { return this.d + this.a }, - dC2(): string { + dC2() { return this.aP1 + 'dC2' } } @@ -926,7 +926,7 @@ describe('emits', () => { }, mounted() { // #3599 - this.$nextTick(function() { + this.$nextTick(function () { // this should be bound to this instance this.$emit('click', 1) From 0e422fbeabd883bb3791537be0c13e4ddff34e75 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 2 Aug 2021 09:01:24 -0400 Subject: [PATCH 2/2] Update computed.ts --- packages/reactivity/src/computed.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/reactivity/src/computed.ts b/packages/reactivity/src/computed.ts index d5eb6285191..3b3734388a1 100644 --- a/packages/reactivity/src/computed.ts +++ b/packages/reactivity/src/computed.ts @@ -12,7 +12,7 @@ export interface WritableComputedRef extends Ref { readonly effect: ReactiveEffect } -export type ComputedGetter = (...ctx: any) => T +export type ComputedGetter = (...args: any[]) => T export type ComputedSetter = (v: T) => void export interface WritableComputedOptions {