Skip to content

fix(reactivity): ensure unref correctly resolves type for ShallowRef #11360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions packages/compiler-dom/__tests__/decoderHtmlBrowser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ describe('decodeHtmlBrowser', () => {
true,
),
).toBe('<strong><strong>&</strong></strong>')
expect(decodeHtmlBrowser('"', true)).toBe(
'"',
)
expect(decodeHtmlBrowser("'", true)).toBe(
"'",
)
expect(decodeHtmlBrowser('"', true)).toBe('"')
expect(decodeHtmlBrowser("'", true)).toBe("'")
})
})
4 changes: 4 additions & 0 deletions packages/dts-test/ref.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,7 @@ describe('toRef <-> toValue', () => {
),
)
})

// unref
declare const text: ShallowRef<string> | ComputedRef<string> | MaybeRef<string>
expectType<string>(unref(text))
6 changes: 4 additions & 2 deletions packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* @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
}

Expand All @@ -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.
* @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)
}

Expand Down