]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): improve type of unref()
authorEvan You <yyx990803@gmail.com>
Thu, 1 Jul 2021 19:20:49 +0000 (15:20 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 1 Jul 2021 19:20:49 +0000 (15:20 -0400)
fix #3954

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

index fd8ac8218afe58a2e1266b52a7b6223ce5d84276..0414ece2e5a3421eb66db3511808247658463578 100644 (file)
@@ -85,7 +85,7 @@ export function triggerRef(ref: Ref) {
   trigger(toRaw(ref), TriggerOpTypes.SET, 'value', __DEV__ ? ref.value : void 0)
 }
 
-export function unref<T>(ref: T): T extends Ref<infer V> ? V : T {
+export function unref<T>(ref: T | Ref<T>): T {
   return isRef(ref) ? (ref.value as any) : ref
 }
 
index a0887ca4babf5f7bc00a9248f32814a5e0652174..74bb78298dac7f0be3d2c6e4d4cefd011b1efbac 100644 (file)
@@ -203,3 +203,10 @@ switch (data.state.value) {
     data.state.value = 'state1'
     break
 }
+
+// #3954
+function testUnrefGenerics<T>(p: T | Ref<T>) {
+  expectType<T>(unref(p))
+}
+
+testUnrefGenerics(1)