@@ -6,6 +6,11 @@ import { reactive } from './reactive';
6
6
7
7
type BailTypes = Function | Map < any , any > | Set < any > | WeakMap < any , any > | WeakSet < any > ;
8
8
9
+ // corner case when use narrows type
10
+ // Ex. type RelativePath = string & { __brand: unknown }
11
+ // RelativePath extends object -> true
12
+ type BaseTypes = string | number | boolean ;
13
+
9
14
export interface Ref < T > {
10
15
value : T ;
11
16
}
@@ -16,63 +21,63 @@ export interface Ref<T> {
16
21
// practical use cases...
17
22
export type UnwrapRef < T > = T extends Ref < infer V >
18
23
? UnwrapRef2 < V >
19
- : T extends BailTypes
24
+ : T extends BailTypes | BaseTypes
20
25
? T // bail out on types that shouldn't be unwrapped
21
26
: T extends object ? { [ K in keyof T ] : UnwrapRef2 < T [ K ] > } : T
22
27
23
28
// prettier-ignore
24
29
type UnwrapRef2 < T > = T extends Ref < infer V >
25
30
? UnwrapRef3 < V >
26
- : T extends BailTypes
31
+ : T extends BailTypes | BaseTypes
27
32
? T
28
33
: T extends object ? { [ K in keyof T ] : UnwrapRef3 < T [ K ] > } : T
29
34
30
35
// prettier-ignore
31
36
type UnwrapRef3 < T > = T extends Ref < infer V >
32
37
? UnwrapRef4 < V >
33
- : T extends BailTypes
38
+ : T extends BailTypes | BaseTypes
34
39
? T
35
40
: T extends object ? { [ K in keyof T ] : UnwrapRef4 < T [ K ] > } : T
36
41
37
42
// prettier-ignore
38
43
type UnwrapRef4 < T > = T extends Ref < infer V >
39
44
? UnwrapRef5 < V >
40
- : T extends BailTypes
45
+ : T extends BailTypes | BaseTypes
41
46
? T
42
47
: T extends object ? { [ K in keyof T ] : UnwrapRef5 < T [ K ] > } : T
43
48
44
49
// prettier-ignore
45
50
type UnwrapRef5 < T > = T extends Ref < infer V >
46
51
? UnwrapRef6 < V >
47
- : T extends BailTypes
52
+ : T extends BailTypes | BaseTypes
48
53
? T
49
54
: T extends object ? { [ K in keyof T ] : UnwrapRef6 < T [ K ] > } : T
50
55
51
56
// prettier-ignore
52
57
type UnwrapRef6 < T > = T extends Ref < infer V >
53
58
? UnwrapRef7 < V >
54
- : T extends BailTypes
59
+ : T extends BailTypes | BaseTypes
55
60
? T
56
61
: T extends object ? { [ K in keyof T ] : UnwrapRef7 < T [ K ] > } : T
57
62
58
63
// prettier-ignore
59
64
type UnwrapRef7 < T > = T extends Ref < infer V >
60
65
? UnwrapRef8 < V >
61
- : T extends BailTypes
66
+ : T extends BailTypes | BaseTypes
62
67
? T
63
68
: T extends object ? { [ K in keyof T ] : UnwrapRef8 < T [ K ] > } : T
64
69
65
70
// prettier-ignore
66
71
type UnwrapRef8 < T > = T extends Ref < infer V >
67
72
? UnwrapRef9 < V >
68
- : T extends BailTypes
73
+ : T extends BailTypes | BaseTypes
69
74
? T
70
75
: T extends object ? { [ K in keyof T ] : UnwrapRef9 < T [ K ] > } : T
71
76
72
77
// prettier-ignore
73
78
type UnwrapRef9 < T > = T extends Ref < infer V >
74
79
? UnwrapRef10 < V >
75
- : T extends BailTypes
80
+ : T extends BailTypes | BaseTypes
76
81
? T
77
82
: T extends object ? { [ K in keyof T ] : UnwrapRef10 < T [ K ] > } : T
78
83
0 commit comments