]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types/reactivity): fix ref type inference on nested reactive properties with...
authorEvan You <yyx990803@gmail.com>
Mon, 4 May 2020 12:51:01 +0000 (08:51 -0400)
committerEvan You <yyx990803@gmail.com>
Mon, 4 May 2020 12:51:17 +0000 (08:51 -0400)
fix #1111

packages/reactivity/src/ref.ts
test-dts/ref.test-d.ts

index 629a2dad9b0a63e2cfa583a81c1718293d0c7650..dc446974ae567129bd161355aa3d598d49f52b38 100644 (file)
@@ -5,11 +5,15 @@ import { reactive, isProxy, toRaw } from './reactive'
 import { ComputedRef } from './computed'
 import { CollectionTypes } from './collectionHandlers'
 
+const RefSymbol = Symbol()
+
 export interface Ref<T = any> {
   /**
-   * @internal
+   * Type differentiator only.
+   * We need this to be in public d.ts but don't want it to show up in IDE
+   * autocomplete, so we use a private Symbol instead.
    */
-  __v_isRef: true
+  [RefSymbol]: true
   value: T
 }
 
index 41dc6ee75c47cc376f30ce2d553bc2c1c96bc185..e2454e035c83441a675bfc092a71d369a739f56a 100644 (file)
@@ -1,5 +1,5 @@
 import { expectType } from 'tsd'
-import { Ref, ref, isRef, unref } from './index'
+import { Ref, ref, isRef, unref, reactive } from './index'
 
 function plainType(arg: number | Ref<number>) {
   // ref coercing
@@ -84,3 +84,12 @@ function withSymbol() {
 }
 
 withSymbol()
+
+const state = reactive({
+  foo: {
+    value: 1,
+    label: 'bar'
+  }
+})
+
+expectType<string>(state.foo.label)