@@ -6,27 +6,27 @@ type BaseNamePath = string | number | boolean | (string | number | boolean)[];
6
6
export type DeepNamePath <
7
7
Store = any ,
8
8
ParentNamePath extends any [ ] = [ ] ,
9
- > = ParentNamePath [ 'length' ] extends 10
9
+ > = ParentNamePath [ 'length' ] extends 5
10
10
? never
11
11
: // Follow code is batch check if `Store` is base type
12
- true extends ( Store extends BaseNamePath ? true : false )
13
- ? ParentNamePath [ 'length' ] extends 0
14
- ? Store | BaseNamePath // Return `BaseNamePath` instead of array if `ParentNamePath` is empty
15
- : Store extends any [ ]
16
- ? [ ...ParentNamePath , number ] // Connect path
17
- : never
18
- : Store extends any [ ] // Check if `Store` is `any[]`
19
- ? // Connect path. e.g. { a: { b: string }[] }
20
- // Get: [a] | [ a,number] | [ a ,number , b]
21
- [ ...ParentNamePath , number ] | DeepNamePath < Store [ number ] , [ ...ParentNamePath , number ] >
22
- : keyof Store extends never // unknown
23
- ? Store
24
- : {
25
- // Convert `Store` to <key, value>. We mark key a `FieldKey`
26
- [ FieldKey in keyof Store ] : Store [ FieldKey ] extends Function
27
- ? never
28
- :
29
- | ( ParentNamePath [ 'length' ] extends 0 ? FieldKey : never ) // If `ParentNamePath` is empty, it can use `FieldKey` without array path
30
- | [ ...ParentNamePath , FieldKey ] // Exist `ParentNamePath`, connect it
31
- | DeepNamePath < Required < Store > [ FieldKey ] , [ ...ParentNamePath , FieldKey ] > ; // If `Store[FieldKey]` is object
32
- } [ keyof Store ] ;
12
+ true extends ( Store extends BaseNamePath ? true : false )
13
+ ? ParentNamePath [ 'length' ] extends 0
14
+ ? Store | BaseNamePath // Return `BaseNamePath` instead of array if `ParentNamePath` is empty
15
+ : Store extends any [ ]
16
+ ? [ ...ParentNamePath , number ] // Connect path
17
+ : never
18
+ : Store extends any [ ] // Check if `Store` is `any[]`
19
+ ? // Connect path. e.g. { a: { b: string }[] }
20
+ // Get: [a] | [ a,number] | [ a ,number , b]
21
+ [ ...ParentNamePath , number ] | DeepNamePath < Store [ number ] , [ ...ParentNamePath , number ] >
22
+ : keyof Store extends never // unknown
23
+ ? Store
24
+ : {
25
+ // Convert `Store` to <key, value>. We mark key a `FieldKey`
26
+ [ FieldKey in keyof Store ] : Store [ FieldKey ] extends Function
27
+ ? never
28
+ :
29
+ | ( ParentNamePath [ 'length' ] extends 0 ? FieldKey : never ) // If `ParentNamePath` is empty, it can use `FieldKey` without array path
30
+ | [ ...ParentNamePath , FieldKey ] // Exist `ParentNamePath`, connect it
31
+ | DeepNamePath < Required < Store > [ FieldKey ] , [ ...ParentNamePath , FieldKey ] > ; // If `Store[FieldKey]` is object
32
+ } [ keyof Store ] ;
0 commit comments