Skip to content

Commit a509e30

Browse files
authoredJul 17, 2024··
fix(reactivity): ensure unref correctly resolves type for ShallowRef (#11360)
close #11356
1 parent 3ee7b4c commit a509e30

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
 

‎packages/dts-test/ref.test-d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,7 @@ describe('toRef <-> toValue', () => {
452452
),
453453
)
454454
})
455+
456+
// unref
457+
declare const text: ShallowRef<string> | ComputedRef<string> | MaybeRef<string>
458+
expectType<string>(unref(text))

‎packages/reactivity/src/ref.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export type MaybeRefOrGetter<T = any> = MaybeRef<T> | (() => T)
235235
* @param ref - Ref or plain value to be converted into the plain value.
236236
* @see {@link https://vuejs.org/api/reactivity-utilities.html#unref}
237237
*/
238-
export function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T {
238+
export function unref<T>(ref: MaybeRef<T> | ComputedRef<T> | ShallowRef<T>): T {
239239
return isRef(ref) ? ref.value : ref
240240
}
241241

@@ -255,7 +255,9 @@ export function unref<T>(ref: MaybeRef<T> | ComputedRef<T>): T {
255255
* @param source - A getter, an existing ref, or a non-function value.
256256
* @see {@link https://vuejs.org/api/reactivity-utilities.html#tovalue}
257257
*/
258-
export function toValue<T>(source: MaybeRefOrGetter<T> | ComputedRef<T>): T {
258+
export function toValue<T>(
259+
source: MaybeRefOrGetter<T> | ComputedRef<T> | ShallowRef<T>,
260+
): T {
259261
return isFunction(source) ? source() : unref(source)
260262
}
261263

0 commit comments

Comments
 (0)
Please sign in to comment.