File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,9 @@ export function isRef(r: any): r is Ref {
65
65
return Boolean ( r && r . __v_isRef === true )
66
66
}
67
67
68
- export function ref < T extends object > ( value : T ) : ToRef < T >
68
+ export function ref < T extends object > (
69
+ value : T
70
+ ) : [ T ] extends [ Ref ] ? T : Ref < UnwrapRef < T > >
69
71
export function ref < T > ( value : T ) : Ref < UnwrapRef < T > >
70
72
export function ref < T = any > ( ) : Ref < T | undefined >
71
73
export function ref ( value ?: unknown ) {
@@ -212,7 +214,7 @@ class ObjectRefImpl<T extends object, K extends keyof T> {
212
214
}
213
215
}
214
216
215
- export type ToRef < T > = [ T ] extends [ Ref ] ? T : Ref < UnwrapRef < T > >
217
+ export type ToRef < T > = [ T ] extends [ Ref ] ? T : Ref < T >
216
218
export function toRef < T extends object , K extends keyof T > (
217
219
object : T ,
218
220
key : K
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
10
10
toRef ,
11
11
toRefs ,
12
12
ToRefs ,
13
+ shallowReactive ,
13
14
watch
14
15
} from './index'
15
16
@@ -236,3 +237,15 @@ function testUnrefGenerics<T>(p: T | Ref<T>) {
236
237
}
237
238
238
239
testUnrefGenerics ( 1 )
240
+
241
+ // #4732
242
+ const baz = shallowReactive ( {
243
+ foo : {
244
+ bar : ref ( 42 )
245
+ }
246
+ } )
247
+
248
+ const foo = toRef ( baz , 'foo' )
249
+
250
+ expectType < Ref < number > > ( foo . value . bar )
251
+ expectType < number > ( foo . value . bar . value )
You can’t perform that action at this time.
0 commit comments