File tree 2 files changed +10
-8
lines changed
2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -244,13 +244,19 @@ expectType<typeof r1>(p1)
244
244
// proxyRefs: `ShallowUnwrapRef`
245
245
const r2 = {
246
246
a : ref ( 1 ) ,
247
+ c : computed ( ( ) => 1 ) ,
248
+ u : undefined ,
247
249
obj : {
248
250
k : ref ( 'foo' )
249
- }
251
+ } ,
252
+ union : Math . random ( ) > 0 - 5 ? ref ( { name : 'yo' } ) : null
250
253
}
251
254
const p2 = proxyRefs ( r2 )
252
255
expectType < number > ( p2 . a )
256
+ expectType < number > ( p2 . c )
257
+ expectType < undefined > ( p2 . u )
253
258
expectType < Ref < string > > ( p2 . obj . k )
259
+ expectType < { name : string } | null > ( p2 . union )
254
260
255
261
// toRef and toRefs
256
262
{
Original file line number Diff line number Diff line change @@ -477,15 +477,11 @@ type BaseTypes = string | number | boolean
477
477
export interface RefUnwrapBailTypes { }
478
478
479
479
export type ShallowUnwrapRef < T > = {
480
- [ K in keyof T ] : T [ K ] extends Ref < infer V >
481
- ? V // if `V` is `unknown` that means it does not extend `Ref` and is undefined
482
- : T [ K ] extends Ref < infer V > | undefined
483
- ? unknown extends V
484
- ? undefined
485
- : V | undefined
486
- : T [ K ]
480
+ [ K in keyof T ] : DistrubuteRef < T [ K ] >
487
481
}
488
482
483
+ type DistrubuteRef < T > = T extends Ref < infer V > ? V : T
484
+
489
485
export type UnwrapRef < T > = T extends ShallowRef < infer V >
490
486
? V
491
487
: T extends Ref < infer V >
You can’t perform that action at this time.
0 commit comments