Prechádzať zdrojové kódy

fix(types/reactivity): fix ref type inference on nested reactive properties with .value

fix #1111
Evan You 6 rokov pred
rodič
commit
bc1f097e29
2 zmenil súbory, kde vykonal 16 pridanie a 3 odobranie
  1. 6 2
      packages/reactivity/src/ref.ts
  2. 10 1
      test-dts/ref.test-d.ts

+ 6 - 2
packages/reactivity/src/ref.ts

@@ -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
 }
 

+ 10 - 1
test-dts/ref.test-d.ts

@@ -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)