File tree 2 files changed +22
-6
lines changed
2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -201,11 +201,23 @@ if (refStatus.value === 'initial') {
201
201
expectType < IsAny < typeof a > > ( false )
202
202
}
203
203
204
- describe ( 'shallowRef with generic' , < T > ( ) => {
205
- const r = ref ( { } ) as MaybeRef < T >
206
- expectType < ShallowRef < T > | Ref < T > > ( shallowRef ( r ) )
204
+ describe ( 'shallowRef with generic' , < T extends { name : string } > ( ) => {
205
+ const r = { } as T
206
+ const s = shallowRef ( r )
207
+ expectType < string > ( s . value . name )
208
+ expectType < ShallowRef < T > > ( shallowRef ( r ) )
207
209
} )
208
210
211
+ {
212
+ // should return ShallowRef<T> | Ref<T>, not ShallowRef<T | Ref<T>>
213
+ expectType < ShallowRef < { name : string } > | Ref < { name : string } > > (
214
+ shallowRef ( { } as MaybeRef < { name : string } > )
215
+ )
216
+ expectType < ShallowRef < number > | Ref < string [ ] > | ShallowRef < string > > (
217
+ shallowRef ( '' as Ref < string [ ] > | string | number )
218
+ )
219
+ }
220
+
209
221
// proxyRefs: should return `reactive` directly
210
222
const r1 = reactive ( {
211
223
k : 'v'
Original file line number Diff line number Diff line change @@ -114,9 +114,13 @@ export type ShallowRef<T = any> = Ref<T> & { [ShallowRefMarker]?: true }
114
114
* @param value - The "inner value" for the shallow ref.
115
115
* @see {@link https://vuejs.org/api/reactivity-advanced.html#shallowref }
116
116
*/
117
- export function shallowRef < T > ( value : MaybeRef < T > ) : Ref < T > | ShallowRef < T >
118
- export function shallowRef < T extends Ref > ( value : T ) : T
119
- export function shallowRef < T > ( value : T ) : ShallowRef < T >
117
+ export function shallowRef < T > (
118
+ value : T
119
+ ) : Ref extends T
120
+ ? T extends Ref
121
+ ? IfAny < T , ShallowRef < T > , T >
122
+ : ShallowRef < T >
123
+ : ShallowRef < T >
120
124
export function shallowRef < T = any > ( ) : ShallowRef < T | undefined >
121
125
export function shallowRef ( value ?: unknown ) {
122
126
return createRef ( value , true )
You can’t perform that action at this time.
0 commit comments