Skip to content

types(reactivity): optimize the display type of ref #12005

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion packages/reactivity/src/ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export function isRef(r: any): r is Ref {
return r ? r[ReactiveFlags.IS_REF] === true : false
}

export type TypeRef<T> = Ref<UnwrapRef<T>, UnwrapRef<T> | T>

/**
* Takes an inner value and returns a reactive and mutable ref object, which
* has a single property `.value` that points to the inner value.
Expand All @@ -54,7 +56,7 @@ export function isRef(r: any): r is Ref {
*/
export function ref<T>(
value: T,
): [T] extends [Ref] ? IfAny<T, Ref<T>, T> : Ref<UnwrapRef<T>, UnwrapRef<T> | T>
): [T] extends [Ref] ? IfAny<T, Ref<T>, T> : TypeRef<T>
export function ref<T = any>(): Ref<T | undefined>
export function ref(value?: unknown) {
return createRef(value, false)
Expand Down