Skip to content

Commit 176d476

Browse files
fix(types): fix unref and toValue when input union type contains ComputedRef (#8748)
close #8747 close #8857
1 parent 73fd810 commit 176d476

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

packages/reactivity/src/ref.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ComputedRef } from './computed'
12
import {
23
activeEffect,
34
getDepFromReactive,
@@ -210,7 +211,7 @@ export type MaybeRefOrGetter<T = any> = MaybeRef<T> | (() => T)
210211
* @param ref - Ref or plain value to be converted into the plain value.
211212
* @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
212213
*/
213-
export function unref<T>(ref: MaybeRef<T>): T {
214+
export function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T {
214215
return isRef(ref) ? ref.value : ref
215216
}
216217

@@ -230,7 +231,7 @@ export function unref<T>(ref: MaybeRef<T>): T {
230231
* @param source - A getter, an existing ref, or a non-function value.
231232
* @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
232233
*/
233-
export function toValue<T>(source: MaybeRefOrGetter<T>): T {
234+
export function toValue<T>(source: MaybeRefOrGetter<T> | ComputedRef<T>): T {
234235
return isFunction(source) ? source() : unref(source)
235236
}
236237

0 commit comments

Comments
 (0)