@@ -4,44 +4,66 @@ import {
4
4
ComputedRef ,
5
5
WritableComputedOptions ,
6
6
DebuggerOptions ,
7
- WritableComputedRef ,
8
- ShallowUnwrapRef
7
+ WritableComputedRef
9
8
} from '@vue/runtime-dom'
10
9
11
- declare const RefMarker : unique symbol
12
- type RefValue < T > = T & { [ RefMarker ] ?: any }
10
+ declare const RefType : unique symbol
13
11
14
- declare const ComputedRefMarker : unique symbol
15
- type ComputedRefValue < T > = T & { [ ComputedRefMarker ] ?: any }
12
+ declare const enum RefTypes {
13
+ Ref = 1 ,
14
+ ComputedRef = 2 ,
15
+ WritableComputedRef = 3
16
+ }
17
+
18
+ type RefValue < T > = T extends null | undefined
19
+ ? T
20
+ : T & { [ RefType ] ?: RefTypes . Ref }
21
+
22
+ type ComputedRefValue < T > = T extends null | undefined
23
+ ? T
24
+ : T & { [ RefType ] ?: RefTypes . ComputedRef }
25
+
26
+ type WritableComputedRefValue < T > = T extends null | undefined
27
+ ? T
28
+ : T & { [ RefType ] ?: RefTypes . WritableComputedRef }
16
29
17
- declare const WritableComputedRefMarker : unique symbol
18
- type WritableComputedRefValue < T > = T & { [ WritableComputedRefMarker ] ?: any }
30
+ type NormalObject < T extends object > = T & { [ RefType ] ?: never }
19
31
20
32
/**
21
33
* Vue ref transform macro for binding refs as reactive variables.
22
34
*/
23
35
declare function _$ < T > ( arg : ComputedRef < T > ) : ComputedRefValue < T >
24
36
declare function _$ < T > ( arg : WritableComputedRef < T > ) : WritableComputedRefValue < T >
25
37
declare function _$ < T > ( arg : Ref < T > ) : RefValue < T >
26
- declare function _$ < T extends object > ( arg ?: T ) : ShallowUnwrapRef < T >
38
+ declare function _$ < T extends object > ( arg ?: T ) : DestructureRefs < T >
39
+
40
+ type DestructureRefs < T extends object > = {
41
+ [ K in keyof T ] : T [ K ] extends ComputedRef < infer V >
42
+ ? ComputedRefValue < V >
43
+ : T [ K ] extends WritableComputedRef < infer V >
44
+ ? WritableComputedRefValue < V >
45
+ : T [ K ] extends Ref < infer V >
46
+ ? RefValue < V >
47
+ : T [ K ]
48
+ }
27
49
28
50
/**
29
51
* Vue ref transform macro for accessing underlying refs of reactive varaibles.
30
52
*/
53
+ declare function _$$ < T extends object > ( arg : NormalObject < T > ) : ToRawRefs < T >
54
+ declare function _$$ < T > ( value : RefValue < T > ) : Ref < T >
31
55
declare function _$$ < T > ( value : ComputedRefValue < T > ) : ComputedRef < T >
32
56
declare function _$$ < T > (
33
57
value : WritableComputedRefValue < T >
34
58
) : WritableComputedRef < T >
35
- declare function _$$ < T > ( value : RefValue < T > ) : Ref < T >
36
- declare function _$$ < T extends object > ( arg : T ) : ToRawRefs < T >
37
59
38
60
type ToRawRefs < T extends object > = {
39
- [ K in keyof T ] : T [ K ] extends ComputedRefValue < infer V >
40
- ? ComputedRefValue < V >
61
+ [ K in keyof T ] : T [ K ] extends RefValue < infer V >
62
+ ? Ref < V >
63
+ : T [ K ] extends ComputedRefValue < infer V >
64
+ ? ComputedRef < V >
41
65
: T [ K ] extends WritableComputedRefValue < infer V >
42
66
? WritableComputedRef < V >
43
- : T [ K ] extends RefValue < infer V >
44
- ? Ref < V >
45
67
: T [ K ] extends object
46
68
? T [ K ] extends
47
69
| Function
0 commit comments