File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,10 @@ export function ref(value?: unknown) {
35
35
return createRef ( value )
36
36
}
37
37
38
- export function shallowRef < T > ( value : T ) : T extends Ref ? T : Ref < T >
38
+ export function shallowRef < T extends object > (
39
+ value : T
40
+ ) : T extends Ref ? T : Ref < T >
41
+ export function shallowRef < T > ( value : T ) : Ref < T >
39
42
export function shallowRef < T = any > ( ) : Ref < T | undefined >
40
43
export function shallowRef ( value ?: unknown ) {
41
44
return createRef ( value , true )
Original file line number Diff line number Diff line change 1
1
import {
2
2
Ref ,
3
3
ref ,
4
+ shallowRef ,
4
5
isRef ,
5
6
unref ,
6
7
reactive ,
@@ -120,6 +121,22 @@ const state = reactive({
120
121
121
122
expectType < string > ( state . foo . label )
122
123
124
+ // shallowRef
125
+ type Status = 'initial' | 'ready' | 'invalidating'
126
+ const shallowStatus = shallowRef < Status > ( 'initial' )
127
+ if ( shallowStatus . value === 'initial' ) {
128
+ expectType < Ref < Status > > ( shallowStatus )
129
+ expectType < Status > ( shallowStatus . value )
130
+ shallowStatus . value = 'invalidating'
131
+ }
132
+
133
+ const refStatus = ref < Status > ( 'initial' )
134
+ if ( refStatus . value === 'initial' ) {
135
+ expectType < Ref < Status > > ( shallowStatus )
136
+ expectType < Status > ( shallowStatus . value )
137
+ refStatus . value = 'invalidating'
138
+ }
139
+
123
140
// proxyRefs: should return `reactive` directly
124
141
const r1 = reactive ( {
125
142
k : 'v'
You can’t perform that action at this time.
0 commit comments