From: 丶远方 Date: Fri, 10 Nov 2023 08:56:29 +0000 (+0800) Subject: fix(types): fix `unref` and `toValue` when input union type contains ComputedRef... X-Git-Tag: v3.3.9~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=176d47671271b1abc21b1508e9a493c7efca6451;p=thirdparty%2Fvuejs%2Fcore.git fix(types): fix `unref` and `toValue` when input union type contains ComputedRef (#8748) close #8747 close #8857 --- diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 68844310e6..61e0bf6c13 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) }