react-hook-form 7.25.0 → 8.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +15 -4
  2. package/dist/__typetests__/__fixtures__/index.d.ts +2 -0
  3. package/dist/__typetests__/__fixtures__/index.d.ts.map +1 -0
  4. package/dist/__typetests__/__fixtures__/type.d.ts +12 -0
  5. package/dist/__typetests__/__fixtures__/type.d.ts.map +1 -0
  6. package/dist/__typetests__/types/__fixtures__/index.d.ts +4 -0
  7. package/dist/__typetests__/types/__fixtures__/index.d.ts.map +1 -0
  8. package/dist/__typetests__/types/__fixtures__/pathString.d.ts +4 -0
  9. package/dist/__typetests__/types/__fixtures__/pathString.d.ts.map +1 -0
  10. package/dist/__typetests__/types/__fixtures__/traversable.d.ts +14 -0
  11. package/dist/__typetests__/types/__fixtures__/traversable.d.ts.map +1 -0
  12. package/dist/__typetests__/types/__fixtures__/tuple.d.ts +15 -0
  13. package/dist/__typetests__/types/__fixtures__/tuple.d.ts.map +1 -0
  14. package/dist/__typetests__/types/form.test-d.d.ts +2 -0
  15. package/dist/__typetests__/types/form.test-d.d.ts.map +1 -0
  16. package/dist/__typetests__/types/path/auto.test-d.d.ts +2 -0
  17. package/dist/__typetests__/types/path/auto.test-d.d.ts.map +1 -0
  18. package/dist/__typetests__/types/path/internal/autoCompletePath.test-d.d.ts +2 -0
  19. package/dist/__typetests__/types/path/internal/autoCompletePath.test-d.d.ts.map +1 -0
  20. package/dist/__typetests__/types/path/internal/hasPath.test-d.d.ts +2 -0
  21. package/dist/__typetests__/types/path/internal/hasPath.test-d.d.ts.map +1 -0
  22. package/dist/__typetests__/types/path/internal/keys.test-d.d.ts +2 -0
  23. package/dist/__typetests__/types/path/internal/keys.test-d.d.ts.map +1 -0
  24. package/dist/__typetests__/types/path/internal/pathGetValue.test-d.d.ts +2 -0
  25. package/dist/__typetests__/types/path/internal/pathGetValue.test-d.d.ts.map +1 -0
  26. package/dist/__typetests__/types/path/internal/pathSetValue.test-d.d.ts +2 -0
  27. package/dist/__typetests__/types/path/internal/pathSetValue.test-d.d.ts.map +1 -0
  28. package/dist/__typetests__/types/path/internal/pathTuple.test-d.d.ts +2 -0
  29. package/dist/__typetests__/types/path/internal/pathTuple.test-d.d.ts.map +1 -0
  30. package/dist/__typetests__/types/path/internal/utils.test-d.d.ts +2 -0
  31. package/dist/__typetests__/types/path/internal/utils.test-d.d.ts.map +1 -0
  32. package/dist/__typetests__/types/path/lazy.test-d.d.ts +2 -0
  33. package/dist/__typetests__/types/path/lazy.test-d.d.ts.map +1 -0
  34. package/dist/__typetests__/types/path/value.test-d.d.ts +2 -0
  35. package/dist/__typetests__/types/path/value.test-d.d.ts.map +1 -0
  36. package/dist/__typetests__/types/util.test-d.d.ts +2 -0
  37. package/dist/__typetests__/types/util.test-d.d.ts.map +1 -0
  38. package/dist/__typetests__/utils/join.test-d.d.ts +2 -0
  39. package/dist/__typetests__/utils/join.test-d.d.ts.map +1 -0
  40. package/dist/__typetests__/utils/of.test-d.d.ts +2 -0
  41. package/dist/__typetests__/utils/of.test-d.d.ts.map +1 -0
  42. package/dist/constants.d.ts +1 -0
  43. package/dist/constants.d.ts.map +1 -1
  44. package/dist/controller.d.ts +1 -1
  45. package/dist/controller.d.ts.map +1 -1
  46. package/dist/index.cjs.js +1 -1
  47. package/dist/index.cjs.js.map +1 -1
  48. package/dist/index.esm.mjs +113 -90
  49. package/dist/index.esm.mjs.map +1 -1
  50. package/dist/index.umd.js +1 -1
  51. package/dist/index.umd.js.map +1 -1
  52. package/dist/logic/createFormControl.d.ts.map +1 -1
  53. package/dist/logic/getProxyFormState.d.ts.map +1 -1
  54. package/dist/logic/getResolverOptions.d.ts +2 -2
  55. package/dist/logic/hasValidation.d.ts +1 -1
  56. package/dist/logic/validateField.d.ts.map +1 -1
  57. package/dist/types/controller.d.ts +6 -6
  58. package/dist/types/controller.d.ts.map +1 -1
  59. package/dist/types/fieldArray.d.ts +7 -9
  60. package/dist/types/fieldArray.d.ts.map +1 -1
  61. package/dist/types/form.d.ts +26 -27
  62. package/dist/types/form.d.ts.map +1 -1
  63. package/dist/types/path/auto.d.ts +76 -0
  64. package/dist/types/path/auto.d.ts.map +1 -0
  65. package/dist/types/path/branded.d.ts +61 -0
  66. package/dist/types/path/branded.d.ts.map +1 -0
  67. package/dist/types/path/index.d.ts +7 -3
  68. package/dist/types/path/index.d.ts.map +1 -1
  69. package/dist/types/path/internal/autoCompletePath.d.ts +173 -0
  70. package/dist/types/path/internal/autoCompletePath.d.ts.map +1 -0
  71. package/dist/types/path/internal/hasPath.d.ts +56 -0
  72. package/dist/types/path/internal/hasPath.d.ts.map +1 -0
  73. package/dist/types/path/internal/keys.d.ts +103 -0
  74. package/dist/types/path/internal/keys.d.ts.map +1 -0
  75. package/dist/types/path/internal/pathGetValue.d.ts +76 -0
  76. package/dist/types/path/internal/pathGetValue.d.ts.map +1 -0
  77. package/dist/types/path/internal/pathSetValue.d.ts +96 -0
  78. package/dist/types/path/internal/pathSetValue.d.ts.map +1 -0
  79. package/dist/types/path/internal/pathTuple.d.ts +73 -0
  80. package/dist/types/path/internal/pathTuple.d.ts.map +1 -0
  81. package/dist/types/path/internal/utils.d.ts +84 -0
  82. package/dist/types/path/internal/utils.d.ts.map +1 -0
  83. package/dist/types/path/lazy.d.ts +62 -0
  84. package/dist/types/path/lazy.d.ts.map +1 -0
  85. package/dist/types/path/pathString.d.ts +6 -0
  86. package/dist/types/path/pathString.d.ts.map +1 -0
  87. package/dist/types/path/value.d.ts +49 -0
  88. package/dist/types/path/value.d.ts.map +1 -0
  89. package/dist/types/utils.d.ts +11 -2
  90. package/dist/types/utils.d.ts.map +1 -1
  91. package/dist/types/validator.d.ts +2 -2
  92. package/dist/types/validator.d.ts.map +1 -1
  93. package/dist/useController.d.ts +2 -2
  94. package/dist/useController.d.ts.map +1 -1
  95. package/dist/useFieldArray.d.ts +1 -1
  96. package/dist/useFieldArray.d.ts.map +1 -1
  97. package/dist/useFormState.d.ts +2 -2
  98. package/dist/useFormState.d.ts.map +1 -1
  99. package/dist/useWatch.d.ts +6 -7
  100. package/dist/useWatch.d.ts.map +1 -1
  101. package/dist/utils/index.d.ts +3 -1
  102. package/dist/utils/index.d.ts.map +1 -1
  103. package/dist/utils/join.d.ts +16 -0
  104. package/dist/utils/join.d.ts.map +1 -0
  105. package/dist/utils/of.d.ts +13 -0
  106. package/dist/utils/of.d.ts.map +1 -0
  107. package/package.json +24 -24
  108. package/dist/types/path/common.d.ts +0 -316
  109. package/dist/types/path/common.d.ts.map +0 -1
  110. package/dist/types/path/eager.d.ts +0 -82
  111. package/dist/types/path/eager.d.ts.map +0 -1
  112. package/dist/utils/omitKeys.d.ts +0 -3
  113. package/dist/utils/omitKeys.d.ts.map +0 -1
@@ -0,0 +1,173 @@
1
+ import { IsAny, IsNever } from '../../utils';
2
+ import { PathString } from '../pathString';
3
+ import { HasPath, ValidPathPrefix } from './hasPath';
4
+ import { Keys } from './keys';
5
+ import { PathGetValue } from './pathGetValue';
6
+ import { PathSetValue } from './pathSetValue';
7
+ import { JoinPathTuple, PathTuple, SplitPathString } from './pathTuple';
8
+ import { AccessPattern, Key, Traversable, UnionToIntersection } from './utils';
9
+ /**
10
+ * Type, which given a path, returns the parent path as a string
11
+ * @typeParam PT - path represented as a tuple
12
+ * @example
13
+ * ```
14
+ * SuggestParentPath<['foo', 'bar', 'baz']> = 'foo.bar'
15
+ * SuggestParentPath<['foo', 'bar']> = 'foo'
16
+ * SuggestParentPath<['foo']> = never
17
+ * ```
18
+ * @internal
19
+ */
20
+ export declare type SuggestParentPath<PT extends PathTuple> = JoinPathTuple<PT extends [...infer R, Key] ? R : []>;
21
+ /**
22
+ * Type to implement {@link SuggestChildPaths}.
23
+ * @typeParam PT - the current path as a {@link PathTuple}
24
+ * @typeParam TPT - the type at that path
25
+ * @typeParam C - constraint
26
+ * @internal
27
+ */
28
+ declare type SuggestChildPathsImpl<PT extends PathTuple, TPT, C extends AccessPattern> = JoinPathTuple<[
29
+ ...PT,
30
+ Keys<TPT, C> | Keys<TPT, AccessPattern<Traversable | undefined | null>>
31
+ ]>;
32
+ /**
33
+ * Type, which given a type and a path into the type, returns all paths as
34
+ * strings which can be used to index the type at that path.
35
+ * Filters out paths whose value doesn't match the constraint type or
36
+ * aren't traversable.
37
+ * @typeParam T - type which is indexed by the path
38
+ * @typeParam PT - the current path into the type as a tuple
39
+ * @typeParam C - constraint
40
+ * @example
41
+ * ```
42
+ * SuggestChildPaths<{foo: string, bar: string}, [], AccessPattern<string>>
43
+ * = 'foo' | 'bar'
44
+ * SuggestChildPaths<{foo: string, bar: number}, [], AccessPattern<string>>
45
+ * = 'foo'
46
+ * SuggestChildPaths<{foo: {bar: string}}, ['foo']> = 'foo.bar'
47
+ * SuggestChildPaths<{foo: {bar: string[]}}, ['foo']> = 'foo.bar'
48
+ * ```
49
+ * @internal
50
+ */
51
+ export declare type SuggestChildPaths<T, PT extends PathTuple, C extends AccessPattern = AccessPattern> = PT extends any ? SuggestChildPathsImpl<PT, PathGetValue<T, PT>, C> : never;
52
+ /**
53
+ * Type to implement {@link SuggestPaths} without having to compute the valid
54
+ * path prefix more than once.
55
+ * @typeParam T - type which is indexed by the path
56
+ * @typeParam PT - the current path into the type as a tuple
57
+ * @typeParam C - constraint
58
+ * @typeParam VPT - the valid path prefix for the given path
59
+ * @internal
60
+ */
61
+ declare type SuggestPathsImpl<T, PT extends PathTuple, C extends AccessPattern, VPT extends PathTuple> = SuggestChildPaths<T, VPT, C> | (PT extends VPT ? SuggestParentPath<VPT> : JoinPathTuple<VPT>);
62
+ /**
63
+ * Type which given a type and a path tuple into it returns
64
+ * - its parent/predecessor path string.
65
+ * - all its child/successor paths that point to a type which is either
66
+ * traversable or matches the constraint type.
67
+ * In case the path does not exist it returns all of the above, but for the last
68
+ * valid path prefix.
69
+ * @typeParam T - type which is indexed by the path
70
+ * @typeParam PT - the current path into the type as a tuple
71
+ * @typeParam C - constraint
72
+ * @example
73
+ * ```
74
+ * SuggestPaths<{foo: {bar: string}}, ['foo'], string> = 'foo.bar'
75
+ * SuggestPaths<{foo: {bar: string}}, ['foo', 'ba'], AccessPattern<string>>
76
+ * = 'foo' | 'foo.bar'
77
+ * SuggestPaths<{foo: {bar: string}}, ['foo', 'bar'], AccessPattern<string>>
78
+ * = 'foo'
79
+ * SuggestPaths<{foo: {bar: {baz: string}}}, ['foo', 'bar'], AccessPattern<string>>
80
+ * = 'foo' | 'foo.bar.baz'
81
+ * ```
82
+ * @internal
83
+ */
84
+ export declare type SuggestPaths<T, PT extends PathTuple, C extends AccessPattern = AccessPattern> = SuggestPathsImpl<T, PT, C, ValidPathPrefix<T, PT>>;
85
+ /**
86
+ * Type to test whether the path is a union of paths.
87
+ * @typeParam PS - path
88
+ * @example
89
+ * ```
90
+ * IsPathUnion<'foo'> = false
91
+ * IsPathUnion<'foo' | 'foo'> = false
92
+ * IsPathUnion<'foo' | 'foo.bar'> = true
93
+ * ```
94
+ * @internal
95
+ */
96
+ declare type IsPathUnion<PS extends PathString> = IsNever<UnionToIntersection<PS>>;
97
+ /**
98
+ * Type to check the current path against the constraint type.
99
+ * Returns the path if it is valid and matches the constraint type.
100
+ * @typeParam T - type which is indexed by the path
101
+ * @typeParam PS - the current path into the type as a string,
102
+ * mustn't be a union
103
+ * @typeParam PT - the current path into the type as a tuple,
104
+ * must be equal to SplitPathString<PS>
105
+ * @typeParam C - constraint
106
+ * @example
107
+ * ```
108
+ * AutoCompletePathCheckConstraint<{foo: {bar: string}}, 'foo', ['foo'], AccessPattern<string>>
109
+ * = never
110
+ * AutoCompletePathCheckConstraint<{foo: {bar: string}}, 'foo.ba', ['foo', 'ba'], AccessPattern<string>>
111
+ * = never
112
+ * AutoCompletePathCheckConstraint<{foo: {bar: string}}, 'foo.bar', ['foo', 'bar'], AccessPattern<string>>
113
+ * = 'foo.bar'
114
+ * ```
115
+ * @internal
116
+ */
117
+ declare type AutoCompletePathCheckConstraint<T, PS extends PathString, PT extends PathTuple, C extends AccessPattern> = HasPath<T, PT> extends true ? AccessPattern<PathGetValue<T, PT>, PathSetValue<T, PT>> extends C ? PS extends JoinPathTuple<PT> ? PS : JoinPathTuple<PT> : never : never;
118
+ /**
119
+ * Type to implement {@link AutoCompletePath} without having to compute the
120
+ * path tuple more than once.
121
+ * @typeParam T - type which is indexed by the path
122
+ * @typeParam PS - the current path into the type as a string,
123
+ * mustn't be a union
124
+ * @typeParam PT - the current path into the type as a tuple,
125
+ * must be equal to SplitPathString<PS>
126
+ * @typeParam C - constraint
127
+ * @example
128
+ * ```
129
+ * AutoCompletePathImpl<{foo: {bar: string}}, 'foo', ['foo'], AccessPattern<string>>
130
+ * = 'foo.bar'
131
+ * AutoCompletePathImpl<{foo: {bar: string}}, 'foo.ba', ['foo', 'ba'], AccessPattern<string>>
132
+ * = 'foo' | 'foo.bar'
133
+ * AutoCompletePathImpl<{foo: {bar: string}}, 'foo.bar', ['foo', 'bar'], AccessPattern<string>>
134
+ * = 'foo' | 'foo.bar'
135
+ * AutoCompletePathImpl<{foo: {bar: {baz: string}}}, 'foo.bar', ['foo', 'bar'], AccessPattern<string>>
136
+ * = 'foo' | 'foo.bar.baz'
137
+ * ```
138
+ * @internal
139
+ */
140
+ declare type AutoCompletePathImpl<T, PS extends PathString, PT extends PathTuple, C extends AccessPattern> = SuggestPaths<T, PT, C> | AutoCompletePathCheckConstraint<T, PS, PT, C>;
141
+ /**
142
+ * Type which given a type and a path string into it returns
143
+ * - its parent/predecessor path string.
144
+ * - the path string itself, if it exists within the type and matches
145
+ * the constraint type.
146
+ * - all its child/successor paths that point to a type which is either
147
+ * traversable or matches the constraint type.
148
+ * Also,
149
+ * - in case the path does not exist it returns all of the above for the last
150
+ * valid path.
151
+ * - in case the path is a union of paths it doesn't suggest any
152
+ * parent/predecessor and child/successor paths.
153
+ * Otherwise, the returned type may become to large, or it may accept paths
154
+ * which don't match the constraint type.
155
+ * @typeParam T - type which is indexed by the path
156
+ * @typeParam PS - the current path into the type as a string
157
+ * @typeParam C - constraint
158
+ * @example
159
+ * ```
160
+ * AutoCompletePath<{foo: {bar: string}}, 'foo', AccessPattern<string>>
161
+ * = 'foo.bar'
162
+ * AutoCompletePath<{foo: {bar: string}}, 'foo.ba', AccessPattern<string>>
163
+ * = 'foo' | 'foo.bar'
164
+ * AutoCompletePath<{foo: {bar: string}}, 'foo.bar', AccessPattern<string>>
165
+ * = 'foo' | 'foo.bar'
166
+ * AutoCompletePath<{foo: {bar: {baz: string}}}, 'foo.bar', AccessPattern<string>>
167
+ * = 'foo' | 'foo.bar.baz'
168
+ * ```
169
+ * @internal
170
+ */
171
+ export declare type AutoCompletePath<T, PS extends PathString, C extends AccessPattern = AccessPattern> = IsAny<PS> extends true ? any : IsPathUnion<PS> extends false ? AutoCompletePathImpl<T, PS, SplitPathString<PS>, C> : PS extends any ? AutoCompletePathCheckConstraint<T, PS, SplitPathString<PS>, C> : never;
172
+ export {};
173
+ //# sourceMappingURL=autoCompletePath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoCompletePath.d.ts","sourceRoot":"","sources":["../../../../src/types/path/internal/autoCompletePath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,GAAG,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE/E;;;;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,KAAK,CAAC"}
@@ -0,0 +1,56 @@
1
+ import { IsNever } from '../../utils';
2
+ import { Keys } from './keys';
3
+ import { KeyGetValue } from './pathGetValue';
4
+ import { AsPathTuple, PathTuple } from './pathTuple';
5
+ import { AsKey, Key } from './utils';
6
+ /**
7
+ * Type to check whether a key is present in a type.
8
+ * If a union of keys is passed, all keys have to be present in the type.
9
+ * @typeParam T - type which is introspected
10
+ * @typeParam K - key
11
+ * @example
12
+ * ```
13
+ * HasKey<{foo: string}, 'foo'> = true
14
+ * HasKey<{foo: string}, 'bar'> = false
15
+ * HasKey<{foo: string}, 'foo' | 'bar'> = false
16
+ * ```
17
+ * @internal
18
+ */
19
+ export declare type HasKey<T, K extends Key> = IsNever<Exclude<K, Keys<T>>>;
20
+ /**
21
+ * Type to implement {@link ValidPathPrefix} tail recursively.
22
+ * @typeParam T - type which the path should be checked against
23
+ * @typeParam PT - path which should exist within the given type
24
+ * @typeParam VPT - accumulates the prefix of keys which have been
25
+ * confirmed to exist already
26
+ * @internal
27
+ */
28
+ declare type ValidPathPrefixImpl<T, PT extends PathTuple, VPT extends PathTuple> = PT extends [infer K, ...infer R] ? HasKey<T, AsKey<K>> extends true ? ValidPathPrefixImpl<KeyGetValue<T, AsKey<K>>, AsPathTuple<R>, AsPathTuple<[...VPT, K]>> : VPT : VPT;
29
+ /**
30
+ * Type to find the longest path prefix which is still valid,
31
+ * i.e. exists within the given type.
32
+ * @typeParam T - type which the path should be checked against
33
+ * @typeParam PT - path which should exist within the given type
34
+ * @example
35
+ * ```
36
+ * ValidPathPrefix<{foo: {bar: string}}, ['foo', 'bar']> = ['foo', 'bar']
37
+ * ValidPathPrefix<{foo: {bar: string}}, ['foo', 'ba']> = ['foo']
38
+ * ```
39
+ * @internal
40
+ */
41
+ export declare type ValidPathPrefix<T, PT extends PathTuple> = ValidPathPrefixImpl<T, PT, [
42
+ ]>;
43
+ /**
44
+ * Type to check whether a path through a type exists.
45
+ * @typeParam T - type which the path should be checked against
46
+ * @typeParam PT - path which should exist within the given type
47
+ * @example
48
+ * ```
49
+ * HasPath<{foo: {bar: string}}, ['foo', 'bar']> = true
50
+ * HasPath<{foo: {bar: string}}, ['foo', 'ba']> = false
51
+ * ```
52
+ * @internal
53
+ */
54
+ export declare type HasPath<T, PT extends PathTuple> = ValidPathPrefix<T, PT> extends PT ? true : false;
55
+ export {};
56
+ //# sourceMappingURL=hasPath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasPath.d.ts","sourceRoot":"","sources":["../../../../src/types/path/internal/hasPath.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAErC;;;;;;;;;;;;GAYG;AACH,oBAAY,MAAM,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpE;;;;;;;GAOG;AACH,aAAK,mBAAmB,CACtB,CAAC,EACD,EAAE,SAAS,SAAS,EACpB,GAAG,SAAS,SAAS,IACnB,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,GAChC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GAC9B,mBAAmB,CACjB,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EACxB,WAAW,CAAC,CAAC,CAAC,EACd,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,CACzB,GACD,GAAG,GACL,GAAG,CAAC;AAER;;;;;;;;;;;GAWG;AACH,oBAAY,eAAe,CAAC,CAAC,EAAE,EAAE,SAAS,SAAS,IAAI,mBAAmB,CACxE,CAAC,EACD,EAAE,EACF;CAAE,CACH,CAAC;AAEF;;;;;;;;;;GAUG;AACH,oBAAY,OAAO,CAAC,CAAC,EAAE,EAAE,SAAS,SAAS,IAAI,eAAe,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,EAAE,GAC5E,IAAI,GACJ,KAAK,CAAC"}
@@ -0,0 +1,103 @@
1
+ import { IsAny, IsNever } from '../../utils';
2
+ import { KeyGetValue } from './pathGetValue';
3
+ import { KeySetValue } from './pathSetValue';
4
+ import { AccessPattern, ArrayKey, IsTuple, Key, ToKey, Traversable, UnionToIntersection } from './utils';
5
+ /**
6
+ * Type which given a tuple type returns its own keys, i.e. only its indices.
7
+ * @typeParam T - tuple type
8
+ * @example
9
+ * ```
10
+ * TupleKeys<[number, string]> = '0' | '1'
11
+ * ```
12
+ * @internal
13
+ */
14
+ export declare type TupleKeys<T extends ReadonlyArray<any>> = Exclude<keyof T, keyof any[]>;
15
+ /**
16
+ * Type which extracts all numeric keys from an object.
17
+ * @typeParam T - type
18
+ * @example
19
+ * ```
20
+ * NumericObjectKeys<{0: string, '1': string, foo: string}> = '0' | '1'
21
+ * ```
22
+ * @internal
23
+ */
24
+ declare type NumericObjectKeys<T extends Traversable> = ToKey<Extract<keyof T, ArrayKey | `${ArrayKey}`>>;
25
+ /**
26
+ * Type which extracts all numeric keys from an object, tuple, or array.
27
+ * If a union is passed, it evaluates to the overlapping numeric keys.
28
+ * @typeParam T - type
29
+ * @example
30
+ * ```
31
+ * NumericKeys<{0: string, '1': string, foo: string}> = '0' | '1'
32
+ * NumericKeys<number[]> = `${number}`
33
+ * NumericKeys<[string, number]> = '0' | '1'
34
+ * NumericKeys<{0: string, '1': string} | [number] | number[]> = '0'
35
+ * ```
36
+ * @internal
37
+ */
38
+ export declare type NumericKeys<T extends Traversable> = UnionToIntersection<T extends ReadonlyArray<any> ? IsTuple<T> extends true ? [TupleKeys<T>] : [ToKey<ArrayKey>] : [NumericObjectKeys<T>]>[never];
39
+ /**
40
+ * Type which extracts all keys from an object.
41
+ * If a union is passed, it evaluates to the overlapping keys.
42
+ * @typeParam T - object type
43
+ * @example
44
+ * ```
45
+ * ObjectKeys<{foo: string, bar: string}, string> = 'foo' | 'bar'
46
+ * ObjectKeys<{foo: string, bar: number}, string> = 'foo'
47
+ * ```
48
+ * @internal
49
+ */
50
+ export declare type ObjectKeys<T extends Traversable> = Exclude<ToKey<keyof T>, `${string}.${string}` | ''>;
51
+ /**
52
+ * Type to check whether a type's property matches the constraint type
53
+ * and return its key. Converts the key to a string.
54
+ * @typeParam T - type whose property should be checked
55
+ * @typeParam K - key of the property
56
+ * @typeParam C - constraint
57
+ * @example
58
+ * ```
59
+ * CheckKeyConstraint<{foo: string}, 'foo', AccessPattern<string>> = 'foo'
60
+ * CheckKeyConstraint<{foo: string}, 'foo', AccessPattern<number>> = never
61
+ * CheckKeyConstraint<string[], number, AccessPattern<string>> = `${number}`
62
+ * ```
63
+ * @internal
64
+ */
65
+ export declare type CheckKeyConstraint<T, K extends Key, C extends AccessPattern> = K extends any ? AccessPattern<KeyGetValue<T, K>, KeySetValue<T, K>> extends C ? K : never : never;
66
+ /**
67
+ * Type which evaluates to true when the type is an array or tuple or is a union
68
+ * which contains an array or tuple.
69
+ * @typeParam T - type
70
+ * @example
71
+ * ```
72
+ * ContainsIndexable<{foo: string}> = false
73
+ * ContainsIndexable<{foo: string} | number[]> = true
74
+ * ```
75
+ * @internal
76
+ */
77
+ export declare type ContainsIndexable<T> = IsNever<Extract<T, ReadonlyArray<any>>> extends true ? false : true;
78
+ /**
79
+ * Type to implement {@link Keys} for non-nullable values.
80
+ * @typeParam T - non-nullable type whose property should be checked
81
+ * @internal
82
+ */
83
+ declare type KeysImpl<T> = [T] extends [Traversable] ? ContainsIndexable<T> extends true ? NumericKeys<T> : ObjectKeys<T> : never;
84
+ /**
85
+ * Type to find all properties of a type that match the constraint type
86
+ * and return their keys.
87
+ * If a union is passed, it evaluates to the overlapping keys.
88
+ * @typeParam T - type whose property should be checked
89
+ * @typeParam C - constraint
90
+ * @example
91
+ * ```
92
+ * Keys<{foo: string, bar: string}, AccessPattern<string>> = 'foo' | 'bar'
93
+ * Keys<{foo?: string, bar?: string}> = 'foo' | 'bar'
94
+ * Keys<{foo: string, bar: number}, AccessPattern<string>> = 'foo'
95
+ * Keys<[string, number], string> = '0'
96
+ * Keys<string[], AccessPattern<string>> = `${number}`
97
+ * Keys<{0: string, '1': string} | [number] | number[]> = '0'
98
+ * ```
99
+ * @internal
100
+ */
101
+ export declare type Keys<T, C extends AccessPattern = AccessPattern> = IsAny<T> extends true ? Key : IsNever<T> extends true ? Key : IsNever<NonNullable<T>> extends true ? never : CheckKeyConstraint<T, KeysImpl<NonNullable<T>>, C>;
102
+ export {};
103
+ //# sourceMappingURL=keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keys.d.ts","sourceRoot":"","sources":["../../../../src/types/path/internal/keys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EACL,aAAa,EACb,QAAQ,EACR,OAAO,EACP,GAAG,EACH,KAAK,EACL,WAAW,EACX,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;GAQG;AACH,oBAAY,SAAS,CAAC,CAAC,SAAS,aAAa,CAAC,GAAG,CAAC,IAAI,OAAO,CAC3D,MAAM,CAAC,EACP,MAAM,GAAG,EAAE,CACZ,CAAC;AAEF;;;;;;;;GAQG;AACH,aAAK,iBAAiB,CAAC,CAAC,SAAS,WAAW,IAAI,KAAK,CACnD,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,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;;;;;;GAgBG;AACH,oBAAY,IAAI,CACd,CAAC,EACD,CAAC,SAAS,aAAa,GAAG,aAAa,IACrC,KAAK,CAAC,CAAC,CAAC,SAAS,IAAI,GACrB,GAAG,GACH,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,GACvB,GAAG,GACH,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GACpC,KAAK,GACL,kBAAkB,CAAC,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,76 @@
1
+ import { IsAny, IsNever } from '../../utils';
2
+ import { AsPathTuple, PathTuple } from './pathTuple';
3
+ import { ArrayKey, AsKey, IsTuple, Key, MapKeys } from './utils';
4
+ /**
5
+ * Type to access a type by a key.
6
+ * - Returns undefined if it can't be indexed by that key.
7
+ * - Returns null if the type is null.
8
+ * - Returns undefined if the type is not traversable.
9
+ * @typeParam T - type which is indexed by the key
10
+ * @typeParam K - key into the type
11
+ * ```
12
+ * TryGet<{foo: string}, 'foo'> = string
13
+ * TryGet<{foo: string}, 'bar'> = undefined
14
+ * TryGet<null, 'foo'> = null
15
+ * TryGet<string, 'foo'> = undefined
16
+ * ```
17
+ * @internal
18
+ */
19
+ declare type TryGet<T, K> = K extends keyof T ? T[K] : T extends null | undefined ? T : unknown;
20
+ /**
21
+ * Type to access an array type by a key.
22
+ * @typeParam T - type which is indexed by the key
23
+ * @typeParam K - key into the type
24
+ * ```
25
+ * TryGetArray<string[], '0'> = string
26
+ * TryGetArray<string[], 'foo'> = undefined
27
+ * ```
28
+ * @internal
29
+ */
30
+ declare type TryGetArray<T extends ReadonlyArray<any>, K extends Key> = K extends `${ArrayKey}` ? T[number] : TryGet<T, K>;
31
+ /**
32
+ * Type to evaluate the type which the given key points to.
33
+ * - If either T or K is union, it will evaluate to the union of the types at
34
+ * the given key(s).
35
+ * - If T can be null or undefined, the resulting type will also include null
36
+ * or undefined.
37
+ * - If a key doesn't exist, or may be optional, the resulting type will
38
+ * include undefined.
39
+ * @typeParam T - type which is indexed by the key
40
+ * @typeParam K - key into the type
41
+ * @example
42
+ * ```
43
+ * KeyGetValue<{foo: string}, 'foo'> = string
44
+ * KeyGetValue<{foo: string, bar: number}, 'foo' | 'bar'> = string | number
45
+ * KeyGetValue<{foo: string} | {foo: number}, 'foo'> = string | number
46
+ * KeyGetValue<null | {foo: string}, 'foo'> = null | string
47
+ * KeyGetValue<{bar: string}, 'foo'> = undefined
48
+ * KeyGetValue<{foo?: string}, 'foo'> = undefined | string
49
+ * ```
50
+ * @internal
51
+ */
52
+ export declare type KeyGetValue<T, K extends Key> = IsNever<K> extends true ? unknown : T extends ReadonlyArray<any> ? IsTuple<T> extends true ? TryGet<T, K> : TryGetArray<T, K> : TryGet<MapKeys<T>, K>;
53
+ /**
54
+ * Type to evaluate the type which the given path points to.
55
+ * - If either T or PT is union, it will evaluate to the union of the types at
56
+ * the given path(s).
57
+ * - If T can be null or undefined, the resulting type will also include null
58
+ * or undefined.
59
+ * - If a path doesn't exist, or may be optional, the resulting type will
60
+ * include undefined.
61
+ * @typeParam T - deeply nested type which is indexed by the path
62
+ * @typeParam PT - path into the deeply nested type
63
+ * @example
64
+ * ```
65
+ * PathGetValue<{foo: {bar: string}}, ['foo', 'bar']> = string
66
+ * PathGetValue<{foo: string, bar: number}, ['foo'] | ['bar']> = string | number
67
+ * PathGetValue<{foo: string} | {foo: number}, ['foo']> = string | number
68
+ * PathGetValue<null | {foo: string}, ['foo']> = null | string
69
+ * PathGetValue<{bar: string}, ['foo']> = undefined
70
+ * PathGetValue<{foo?: string}, ['foo']> = undefined | string
71
+ * ```
72
+ * @internal
73
+ */
74
+ export declare type PathGetValue<T, PT extends PathTuple> = IsAny<PT> extends true ? any : IsNever<PT> extends true ? unknown : PT extends [infer K, ...infer R] ? PathGetValue<KeyGetValue<T, AsKey<K>>, AsPathTuple<R>> : T;
75
+ export {};
76
+ //# sourceMappingURL=p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I,KAAK,CAAC,EAAE,CAAC,SAAS,IAAI,GACtE,GAAG,GACH,OAAO,CAAC,EAAE,CAAC,SAAS,IAAI,GACxB,OAAO,GACP,EAAE,SAAS,CAAC,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC,GAChC,YAAY,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,GACtD,CAAC,CAAC"}
@@ -0,0 +1,96 @@
1
+ import { IsAny } from '../../utils';
2
+ import { AsPathTuple, PathTuple } from './pathTuple';
3
+ import { ArrayKey, AsKey, IsTuple, Key, MapKeys, UnionToIntersection } from './utils';
4
+ /**
5
+ * Type to access a type by a key. Returns never
6
+ * - if it can't be indexed by that key.
7
+ * - if the type is not traversable.
8
+ * @typeParam T - type which is indexed by the key
9
+ * @typeParam K - key into the type
10
+ * ```
11
+ * TrySet<{foo: string}, 'foo'> = string
12
+ * TrySet<{foo: string}, 'bar'> = never
13
+ * TrySet<null, 'foo'> = never
14
+ * TrySet<string, 'foo'> = never
15
+ * ```
16
+ * @internal
17
+ */
18
+ declare type TrySet<T, K> = K extends keyof T ? T[K] : never;
19
+ /**
20
+ * Type to access an array type by a key.
21
+ * @typeParam T - type which is indexed by the key
22
+ * @typeParam K - key into the type
23
+ * ```
24
+ * TrySetArray<string[], '0'> = string
25
+ * TrySetArray<string[], 'foo'> = never
26
+ * ```
27
+ * @internal
28
+ */
29
+ declare type TrySetArray<T extends ReadonlyArray<any>, K extends Key> = K extends `${ArrayKey}` ? T[number] : TrySet<T, K>;
30
+ /**
31
+ * Type to implement {@link KeySetValue}. Wraps everything into a tuple.
32
+ * @typeParam T - non-nullable type which is indexed by the key
33
+ * @typeParam K - key into the type, mustn't be a union of keys
34
+ * @internal
35
+ */
36
+ declare type KeySetValueImpl<T, K extends Key> = T extends ReadonlyArray<any> ? IsTuple<T> extends true ? [TrySet<T, K>] : [TrySetArray<T, K>] : [TrySet<MapKeys<T>, K>];
37
+ /**
38
+ * Type to evaluate the type which is required for setting the property which
39
+ * the given key points to.
40
+ * - If either T or K is union, it will evaluate to the intersection of the
41
+ * types at the given key(s).
42
+ * - If T can be null or undefined, the resulting type won't include null or
43
+ * undefined.
44
+ * - If a key doesn't exist,the resulting type will be never.
45
+ * - If a key may be optional, the resulting type will include undefined.
46
+ * @typeParam T - type which is indexed by the key
47
+ * @typeParam K - key into the type
48
+ * @example
49
+ * ```
50
+ * KeySetValue<{foo: string}, 'foo'> = string
51
+ * KeySetValue<{foo: string, bar: number}, 'foo' | 'bar'> = string & number
52
+ * KeySetValue<{foo: string} | {foo: number}, 'foo'> = string & number
53
+ * KeySetValue<null | {foo: string}, 'foo'> = string
54
+ * KeySetValue<{bar: string}, 'foo'> = never
55
+ * KeySetValue<{foo?: string}, 'foo'> = undefined | string
56
+ * ```
57
+ * @internal
58
+ */
59
+ export declare type KeySetValue<T, K extends Key> = UnionToIntersection<K extends any ? KeySetValueImpl<NonNullable<T>, K> : never>[never];
60
+ /**
61
+ * Type to implement {@link PathSetValue} tail-recursively.
62
+ * Wraps everything into a tuple.
63
+ * @typeParam T - deeply nested type which is indexed by the path
64
+ * @typeParam PT - path into the deeply nested type
65
+ * @internal
66
+ */
67
+ declare type PathSetValueImpl<T, PT extends PathTuple> = PT extends [
68
+ infer K,
69
+ ...infer R
70
+ ] ? PathSetValueImpl<KeySetValue<T, AsKey<K>>, AsPathTuple<R>> : [T];
71
+ /**
72
+ * Type to evaluate the type which is required for setting the property which
73
+ * the given path points to.
74
+ * - If either T or PT is union, it will evaluate to the intersection of the
75
+ * types at the given paths(s).
76
+ * - If T can be null or undefined, the resulting type won't include null or
77
+ * undefined.
78
+ * - If a path doesn't exist, the resulting type will be never.
79
+ * - Only if last kay is optional, the resulting type will include undefined.
80
+ * @typeParam T - deeply nested type which is indexed by the path
81
+ * @typeParam PT - path into the deeply nested type
82
+ * @example
83
+ * ```
84
+ * PathSetValue<{foo: {bar: string}}, ['foo', 'bar']> = string
85
+ * PathSetValue<{foo: string, bar: number}, ['foo'] | ['bar']> = string & number
86
+ * PathSetValue<{foo: string} | {foo: number}, ['foo']> = string & number
87
+ * PathSetValue<null | {foo: string}, ['foo']> = string
88
+ * PathSetValue<{bar: string}, ['foo']> = never
89
+ * PathSetValue<{foo?: string}, ['foo']> = undefined | string
90
+ * PathSetValue<{foo?: {bar: string}}, ['foo', 'bar']> = string
91
+ * ```
92
+ * @internal
93
+ */
94
+ export declare type PathSetValue<T, PT extends PathTuple> = IsAny<PT> extends true ? any : UnionToIntersection<PathSetValueImpl<T, PT>>[never];
95
+ export {};
96
+ //# sourceMappingURL=pathSetValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathSetValue.d.ts","sourceRoot":"","sources":["../../../../src/types/path/internal/pathSetValue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EACL,QAAQ,EACR,KAAK,EACL,OAAO,EACP,GAAG,EACH,OAAO,EACP,mBAAmB,EACpB,MAAM,SAAS,CAAC;AAEjB;;;;;;;;;;;;;GAaG;AACH,aAAK,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;AAErD;;;;;;;;;GASG;AACH,aAAK,WAAW,CACd,CAAC,SAAS,aAAa,CAAC,GAAG,CAAC,EAC5B,CAAC,SAAS,GAAG,IACX,CAAC,SAAS,GAAG,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEvD;;;;;GAKG;AACH,aAAK,eAAe,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,aAAa,CAAC,GAAG,CAAC,GACjE,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,GACrB,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GACd,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GACrB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE5B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,oBAAY,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,GAAG,IAAI,mBAAmB,CAC7D,CAAC,SAAS,GAAG,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAC3D,CAAC,KAAK,CAAC,CAAC;AAET;;;;;;GAMG;AACH,aAAK,gBAAgB,CAAC,CAAC,EAAE,EAAE,SAAS,SAAS,IAAI,EAAE,SAAS;IAC1D,MAAM,CAAC;IACP,GAAG,MAAM,CAAC;CACX,GACG,gBAAgB,CAAC,WAAW,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,GAC1D,CAAC,CAAC,CAAC,CAAC;AAER;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,oBAAY,YAAY,CAAC,CAAC,EAAE,EAAE,SAAS,SAAS,IAAI,KAAK,CAAC,EAAE,CAAC,SAAS,IAAI,GACtE,GAAG,GACH,mBAAmB,CAAC,gBAAgB,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC"}
@@ -0,0 +1,73 @@
1
+ import { IsAny } from '../../utils';
2
+ import { PathString } from '../pathString';
3
+ import { AsKey, Key } from './utils';
4
+ /**
5
+ * Type which describes a path through an object as a list of individual keys.
6
+ * @internal
7
+ */
8
+ export declare type PathTuple = Key[];
9
+ /**
10
+ * Type to assert that a type is a path tuple.
11
+ * @typeParam T - type which may be a path tuple
12
+ * @internal
13
+ */
14
+ export declare type AsPathTuple<T> = Extract<T, PathTuple>;
15
+ /**
16
+ * Type which appends a key to the path tuple only if it is not blank,
17
+ * i.e. not the empty string.
18
+ * @typeParam PT - path
19
+ * @typeParam K - key
20
+ * @example
21
+ * ```
22
+ * AppendNonBlankKey<['foo'], 'bar'> = ['foo', 'bar']
23
+ * AppendNonBlankKey<['foo'], ''> = ['foo']
24
+ * ```
25
+ * @internal
26
+ */
27
+ declare type AppendNonBlankKey<PT extends PathTuple, K extends Key> = K extends '' ? PT : [...PT, K];
28
+ /**
29
+ * Type to implement {@link SplitPathString} tail recursively.
30
+ * @typeParam PS - remaining path string which should be split into its
31
+ * individual keys
32
+ * @typeParam PT - accumulator of the keys which have been split from
33
+ * the original path string already
34
+ * @internal
35
+ */
36
+ declare type SplitPathStringImpl<PS extends PathString, PT extends PathTuple> = PS extends `${infer K}.${infer R}` ? SplitPathStringImpl<R, AppendNonBlankKey<PT, K>> : AppendNonBlankKey<PT, PS>;
37
+ /**
38
+ * Type to split a path string into a path tuple.
39
+ * The individual keys may be empty strings.
40
+ * @typeParam PS - path string which should be split into its individual keys
41
+ * @example
42
+ * ```
43
+ * SplitPathString<'foo'> = ['foo']
44
+ * SplitPathString<'foo.bar.0.baz'> = ['foo', 'bar', '0', 'baz']
45
+ * SplitPathString<'.'> = []
46
+ * ```
47
+ * @internal
48
+ */
49
+ export declare type SplitPathString<PS extends PathString> = IsAny<PS> extends true ? any : SplitPathStringImpl<PS, []>;
50
+ /**
51
+ * Type to implement {@link JoinPathTuple} tail-recursively.
52
+ * @typeParam PT - remaining keys which needs to be joined
53
+ * @typeParam PS - accumulator of the already joined keys
54
+ * @internal
55
+ */
56
+ declare type JoinPathTupleImpl<PT extends PathTuple, PS extends PathString> = PT extends [infer K, ...infer R] ? JoinPathTupleImpl<AsPathTuple<R>, `${PS}.${AsKey<K>}`> : PS;
57
+ /**
58
+ * Type to join a path tuple to a path string.
59
+ * @typeParam PT - path tuple which should be joined.
60
+ * @example
61
+ * ```
62
+ * JoinPathTuple<['foo']> = 'foo'
63
+ * JoinPathTuple<['foo', 'bar', '0', 'baz']> = 'foo.bar.0.baz'
64
+ * JoinPathTuple<[]> = never
65
+ * ```
66
+ * @internal
67
+ */
68
+ export declare type JoinPathTuple<PT extends PathTuple> = PT extends [
69
+ infer K,
70
+ ...infer R
71
+ ] ? JoinPathTupleImpl<AsPathTuple<R>, AsKey<K>> : never;
72
+ export {};
73
+ //# sourceMappingURL=pathTuple.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathTuple.d.ts","sourceRoot":"","sources":["../../../../src/types/path/internal/pathTuple.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAErC;;;GAGG;AACH,oBAAY,SAAS,GAAG,GAAG,EAAE,CAAC;AAE9B;;;;GAIG;AACH,oBAAY,WAAW,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,aAAK,iBAAiB,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,GACtE,EAAE,GACF,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;AAEf;;;;;;;GAOG;AACH,aAAK,mBAAmB,CACtB,EAAE,SAAS,UAAU,EACrB,EAAE,SAAS,SAAS,IAClB,EAAE,SAAS,GAAG,MAAM,CAAC,IAAI,MAAM,CAAC,EAAE,GAClC,mBAAmB,CAAC,CAAC,EAAE,iBAAiB,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAChD,iBAAiB,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;AAE9B;;;;;;;;;;;GAWG;AACH,oBAAY,eAAe,CAAC,EAAE,SAAS,UAAU,IAAI,KAAK,CAAC,E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