From 176d47671271b1abc21b1508e9a493c7efca6451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=B6=E8=BF=9C=E6=96=B9?= Date: Fri, 10 Nov 2023 16:56:29 +0800 Subject: [PATCH] fix(types): fix `unref` and `toValue` when input union type contains ComputedRef (#8748) close #8747 close #8857 --- packages/reactivity/src/ref.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 68844310e64..61e0bf6c13d 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -1,3 +1,4 @@ +import type { ComputedRef } from './computed' import { activeEffect, getDepFromReactive, @@ -210,7 +211,7 @@ export type MaybeRefOrGetter = MaybeRef | (() => 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(ref: MaybeRef): T { +export function unref(ref: MaybeRef | ComputedRef): T { return isRef(ref) ? ref.value : ref } @@ -230,7 +231,7 @@ export function unref(ref: MaybeRef): 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(source: MaybeRefOrGetter): T { +export function toValue(source: MaybeRefOrGetter | ComputedRef): T { return isFunction(source) ? source() : unref(source) }