]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): unwrap refs on public instance data (#3319)
authorHcySunYang <HcySunYang@outlook.com>
Thu, 25 Mar 2021 21:30:10 +0000 (05:30 +0800)
committerGitHub <noreply@github.com>
Thu, 25 Mar 2021 21:30:10 +0000 (17:30 -0400)
fix #3315

packages/reactivity/src/index.ts
packages/reactivity/src/reactive.ts
packages/runtime-core/src/componentPublicInstance.ts
test-dts/defineComponent.test-d.tsx

index b03e916d14a14db44ddbc2a30a4068dbc82848bf..240410141e457dc6edd0a224e236bc782efebe27 100644 (file)
@@ -25,7 +25,8 @@ export {
   markRaw,
   toRaw,
   ReactiveFlags,
-  DeepReadonly
+  DeepReadonly,
+  UnwrapNestedRefs
 } from './reactive'
 export {
   computed,
index cea41a191ae12ebd753970198be97fae995023cf..d8529b543f5d26bf07a9f98ba42184c2f80b106f 100644 (file)
@@ -57,7 +57,7 @@ function getTargetType(value: Target) {
 }
 
 // only unwrap nested ref
-type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>
+export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRef<T>
 
 /**
  * Creates a reactive copy of the original object.
index 78f75d8e75745f6188e1fdb89cb64fbaa63b439d..fd0351f64d7d6637005a4f56f625b75fea39177d 100644 (file)
@@ -20,7 +20,8 @@ import {
   ReactiveFlags,
   track,
   TrackOpTypes,
-  ShallowUnwrapRef
+  ShallowUnwrapRef,
+  UnwrapNestedRefs
 } from '@vue/reactivity'
 import {
   ExtractComputedReturns,
@@ -195,7 +196,7 @@ export type ComponentPublicInstance<
   ): WatchStopHandle
 } & P &
   ShallowUnwrapRef<B> &
-  D &
+  UnwrapNestedRefs<D> &
   ExtractComputedReturns<C> &
   M &
   ComponentCustomProperties
index 7a07fef2fe1f57a89f152a9d0020ad0d17648cce..8dbf7ca29ffcd296819020aff5e0ada0618150ba 100644 (file)
@@ -379,7 +379,8 @@ describe('type inference w/ options API', () => {
       // here in data() - somehow that would mess up the inference
       expectType<number | undefined>(this.a)
       return {
-        c: this.a || 123
+        c: this.a || 123,
+        someRef: ref(0)
       }
     },
     computed: {
@@ -418,6 +419,7 @@ describe('type inference w/ options API', () => {
       expectType<number>(this.d)
       // computed get/set
       expectType<number>(this.e)
+      expectType<number>(this.someRef)
     },
     methods: {
       doSomething() {