mirror of https://github.com/vuejs/core.git
fix(reactivity): ensure `unref` correctly resolves type for `ShallowRef` (#11360)
close #11356
This commit is contained in:
parent
3ee7b4c7b1
commit
a509e30f05
|
@ -452,3 +452,7 @@ describe('toRef <-> toValue', () => {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// unref
|
||||||
|
declare const text: ShallowRef<string> | ComputedRef<string> | MaybeRef<string>
|
||||||
|
expectType<string>(unref(text))
|
||||||
|
|
|
@ -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.
|
* @param ref - Ref or plain value to be converted into the plain value.
|
||||||
* @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
|
* @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
|
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.
|
* @param source - A getter, an existing ref, or a non-function value.
|
||||||
* @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
|
* @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)
|
return isFunction(source) ? source() : unref(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue