Skip to content

Commit

Permalink
fix(types): fix unref and toValue when input union type contains …
Browse files Browse the repository at this point in the history
…ComputedRef (#8748)

close #8747
close #8857
  • Loading branch information
Alfred-Skyblue authored Nov 10, 2023
1 parent 73fd810 commit 176d476
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ComputedRef } from './computed'
import {
activeEffect,
getDepFromReactive,
Expand Down Expand Up @@ -210,7 +211,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>): T {
export function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T {
return isRef(ref) ? ref.value : ref
}

Expand All @@ -230,7 +231,7 @@ export function unref<T>(ref: MaybeRef<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>): T {
export function toValue<T>(source: MaybeRefOrGetter<T> | ComputedRef<T>): T {
return isFunction(source) ? source() : unref(source)
}

Expand Down

0 comments on commit 176d476

Please sign in to comment.