1
1
import { isTracking , trackEffects , triggerEffects } from './effect'
2
2
import { TrackOpTypes , TriggerOpTypes } from './operations'
3
3
import { isArray , hasChanged } from '@vue/shared'
4
- import { isProxy , toRaw , isReactive , toReactive } from './reactive'
4
+ import {
5
+ isProxy ,
6
+ toRaw ,
7
+ isReactive ,
8
+ toReactive ,
9
+ ShallowReactiveMarker
10
+ } from './reactive'
5
11
import { CollectionTypes } from './collectionHandlers'
6
12
import { createDep , Dep } from './dep'
7
13
@@ -74,11 +80,15 @@ export function ref(value?: unknown) {
74
80
return createRef ( value , false )
75
81
}
76
82
83
+ declare const ShallowRefMarker : unique symbol
84
+
85
+ type ShallowRef < T = any > = Ref < T > & { [ ShallowRefMarker ] ?: true }
86
+
77
87
export function shallowRef < T extends object > (
78
88
value : T
79
- ) : T extends Ref ? T : Ref < T >
80
- export function shallowRef < T > ( value : T ) : Ref < T >
81
- export function shallowRef < T = any > ( ) : Ref < T | undefined >
89
+ ) : T extends Ref ? T : ShallowRef < T >
90
+ export function shallowRef < T > ( value : T ) : ShallowRef < T >
91
+ export function shallowRef < T = any > ( ) : ShallowRef < T | undefined >
82
92
export function shallowRef ( value ?: unknown ) {
83
93
return createRef ( value , true )
84
94
}
@@ -215,6 +225,7 @@ class ObjectRefImpl<T extends object, K extends keyof T> {
215
225
}
216
226
217
227
export type ToRef < T > = [ T ] extends [ Ref ] ? T : Ref < T >
228
+
218
229
export function toRef < T extends object , K extends keyof T > (
219
230
object : T ,
220
231
key : K
@@ -258,7 +269,9 @@ export type ShallowUnwrapRef<T> = {
258
269
: T [ K ]
259
270
}
260
271
261
- export type UnwrapRef < T > = T extends Ref < infer V >
272
+ export type UnwrapRef < T > = T extends ShallowRef < infer V >
273
+ ? V
274
+ : T extends Ref < infer V >
262
275
? UnwrapRefSimple < V >
263
276
: UnwrapRefSimple < T >
264
277
@@ -271,7 +284,7 @@ export type UnwrapRefSimple<T> = T extends
271
284
? T
272
285
: T extends Array < any >
273
286
? { [ K in keyof T ] : UnwrapRefSimple < T [ K ] > }
274
- : T extends object
287
+ : T extends object & { [ ShallowReactiveMarker ] ?: never }
275
288
? {
276
289
[ P in keyof T ] : P extends symbol ? T [ P ] : UnwrapRef < T [ P ] >
277
290
}
0 commit comments