diff --git a/packages/reactivity/src/index.ts b/packages/reactivity/src/index.ts index f0445e87da0..7480bb2f9e3 100644 --- a/packages/reactivity/src/index.ts +++ b/packages/reactivity/src/index.ts @@ -36,6 +36,7 @@ export { type Raw, type DeepReadonly, type ShallowReactive, + type IsShallowReactive, type UnwrapNestedRefs, type Reactive, type ReactiveMarker, diff --git a/packages/reactivity/src/reactive.ts b/packages/reactivity/src/reactive.ts index 729c854965e..07e6c2f51ac 100644 --- a/packages/reactivity/src/reactive.ts +++ b/packages/reactivity/src/reactive.ts @@ -107,6 +107,10 @@ export declare const ShallowReactiveMarker: unique symbol export type ShallowReactive = T & { [ShallowReactiveMarker]?: true } +export type IsShallowReactive = T extends { [ShallowReactiveMarker]?: true } + ? true + : false + /** * Shallow version of {@link reactive()}. * diff --git a/packages/reactivity/src/ref.ts b/packages/reactivity/src/ref.ts index 6b8d541819d..1addaf4ef9d 100644 --- a/packages/reactivity/src/ref.ts +++ b/packages/reactivity/src/ref.ts @@ -8,6 +8,7 @@ import { import { Dep, getDepFromReactive } from './dep' import { type Builtin, + type ShallowReactive, type ShallowReactiveMarker, isProxy, isReactive, @@ -489,10 +490,16 @@ export type ShallowUnwrapRef = { [K in keyof T]: DistributeRef } -type DistributeRef = T extends Ref ? V : T +type DistributeRef = + T extends Ref + ? V extends object + ? ShallowReactive + : V + : T -export type UnwrapRef = - T extends ShallowRef +export type UnwrapRef = T extends undefined + ? T + : T extends ShallowRef ? V : T extends Ref ? UnwrapRefSimple diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 3871167b3ee..0d71412fb97 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -210,6 +210,7 @@ export type { ReactiveFlags, DeepReadonly, ShallowReactive, + IsShallowReactive, UnwrapNestedRefs, ComputedRef, WritableComputedRef,