From 80e346e2cd349915058624587ceb5fae2b37a329 Mon Sep 17 00:00:00 2001 From: HcySunYang Date: Sat, 27 Feb 2021 11:16:51 +0800 Subject: [PATCH] types: the data type of the public instance should be unwrapped --- packages/reactivity/src/index.ts | 3 ++- packages/reactivity/src/reactive.ts | 2 +- packages/runtime-core/src/componentPublicInstance.ts | 5 +++-- test-dts/defineComponent.test-d.tsx | 4 +++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/reactivity/src/index.ts b/packages/reactivity/src/index.ts index b03e916d14a..240410141e4 100644 --- a/packages/reactivity/src/index.ts +++ b/packages/reactivity/src/index.ts @@ -25,7 +25,8 @@ export { markRaw, toRaw, ReactiveFlags, - DeepReadonly + DeepReadonly, + UnwrapNestedRefs } from './reactive' export { computed, diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index cea41a191ae..d8529b543f5 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -57,7 +57,7 @@ function getTargetType(value: Target) { } // only unwrap nested ref -type UnwrapNestedRefs = T extends Ref ? T : UnwrapRef +export type UnwrapNestedRefs = T extends Ref ? T : UnwrapRef /** * Creates a reactive copy of the original object. diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index c493fea0b90..695e4084183 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -20,7 +20,8 @@ import { ReactiveFlags, track, TrackOpTypes, - ShallowUnwrapRef + ShallowUnwrapRef, + UnwrapNestedRefs } from '@vue/reactivity' import { ExtractComputedReturns, @@ -197,7 +198,7 @@ export type ComponentPublicInstance< ): WatchStopHandle } & P & ShallowUnwrapRef & - D & + UnwrapNestedRefs & ExtractComputedReturns & M & ComponentCustomProperties diff --git a/test-dts/defineComponent.test-d.tsx b/test-dts/defineComponent.test-d.tsx index 949654b1b9e..2271cda5c27 100644 --- a/test-dts/defineComponent.test-d.tsx +++ b/test-dts/defineComponent.test-d.tsx @@ -341,7 +341,8 @@ describe('type inference w/ options API', () => { // here in data() - somehow that would mess up the inference expectType(this.a) return { - c: this.a || 123 + c: this.a || 123, + someRef: ref(0) } }, computed: { @@ -380,6 +381,7 @@ describe('type inference w/ options API', () => { expectType(this.d) // computed get/set expectType(this.e) + expectType(this.someRef) }, methods: { doSomething() {