]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(reactivity): ensure `unref` correctly resolves type for `ShallowRef` (#11360)
authorTycho <jh.leong@outlook.com>
Wed, 17 Jul 2024 02:09:57 +0000 (10:09 +0800)
committerGitHub <noreply@github.com>
Wed, 17 Jul 2024 02:09:57 +0000 (10:09 +0800)
close #11356

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

index 5d4c9d95dabd476b3906fc798ef0438bb84b1271..1456c523239bda8a991ac4683d72ee28f032b610 100644 (file)
@@ -452,3 +452,7 @@ describe('toRef <-> toValue', () => {
     ),
   )
 })
+
+// unref
+declare const text: ShallowRef<string> | ComputedRef<string> | MaybeRef<string>
+expectType<string>(unref(text))
index e47b8aa55823cb667222f7385bb308dfe6c9037e..3e9b05062f3991dbfed7272afd4585716d82a954 100644 (file)
@@ -235,7 +235,7 @@ export type MaybeRefOrGetter<T = any> = MaybeRef<T> | (() => T)
  * @param ref - Ref or plain value to be converted into the plain value.
  * @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
  */
-export function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T {
+export function unref<T>(ref: MaybeRef<T> | ComputedRef<T> | ShallowRef<T>): T {
   return isRef(ref) ? ref.value : ref
 }
 
@@ -255,7 +255,9 @@ export function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T {
  * @param source - A getter, an existing ref, or a non-function value.
  * @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
  */
-export function toValue<T>(source: MaybeRefOrGetter<T> | ComputedRef<T>): T {
+export function toValue<T>(
+  source: MaybeRefOrGetter<T> | ComputedRef<T> | ShallowRef<T>,
+): T {
   return isFunction(source) ? source() : unref(source)
 }