type-fest 5.4.3 → 5.4.4
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.
- package/package.json +1 -1
- package/source/is-union.d.ts +2 -1
- package/source/package-json.d.ts +2 -2
- package/source/paths.d.ts +40 -57
package/package.json
CHANGED
package/source/is-union.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type {IsNever} from './is-never.d.ts';
|
|
2
|
+
import type {IsEqual} from './is-equal.d.ts';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
Returns a boolean for whether the given type is a union.
|
|
@@ -24,7 +25,7 @@ type InternalIsUnion<T, U = T> =
|
|
|
24
25
|
IsNever<T> extends true
|
|
25
26
|
? false
|
|
26
27
|
: T extends any
|
|
27
|
-
?
|
|
28
|
+
? IsEqual<U, T> extends true
|
|
28
29
|
? false
|
|
29
30
|
: true
|
|
30
31
|
: never
|
package/source/package-json.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {LiteralUnion} from './literal-union.d.ts';
|
|
2
1
|
import type {JsonObject, JsonValue} from './json-value.d.ts';
|
|
2
|
+
import type {LiteralUnion} from './literal-union.d.ts';
|
|
3
3
|
|
|
4
4
|
export namespace PackageJson {
|
|
5
5
|
/**
|
|
@@ -526,7 +526,7 @@ export namespace PackageJson {
|
|
|
526
526
|
Engines that this package runs on.
|
|
527
527
|
*/
|
|
528
528
|
engines?: {
|
|
529
|
-
[EngineName in 'npm' | 'node'
|
|
529
|
+
[EngineName in LiteralUnion<'npm' | 'node', string>]?: string;
|
|
530
530
|
};
|
|
531
531
|
|
|
532
532
|
/**
|
package/source/paths.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {NonRecursiveType, ToString, IsNumberLike, ApplyDefaultOptions, MapsSetsOrArrays} from './internal/index.d.ts';
|
|
2
2
|
import type {IsAny} from './is-any.d.ts';
|
|
3
3
|
import type {UnknownArray} from './unknown-array.d.ts';
|
|
4
4
|
import type {GreaterThan} from './greater-than.d.ts';
|
|
@@ -192,67 +192,50 @@ open('listB.1'); // TypeError. Because listB only has one element.
|
|
|
192
192
|
export type Paths<T, Options extends PathsOptions = {}> = _Paths<T, ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, Options>>;
|
|
193
193
|
|
|
194
194
|
type _Paths<T, Options extends Required<PathsOptions>, CurrentDepth extends number = 0> =
|
|
195
|
-
T extends NonRecursiveType |
|
|
195
|
+
T extends NonRecursiveType | Exclude<MapsSetsOrArrays, UnknownArray>
|
|
196
196
|
? never
|
|
197
197
|
: IsAny<T> extends true
|
|
198
198
|
? never
|
|
199
|
-
: T extends
|
|
200
|
-
?
|
|
201
|
-
|
|
202
|
-
? InternalPaths<StaticPartOfArray<T>, Options, CurrentDepth> | InternalPaths<Array<VariablePartOfArray<T>[number]>, Options, CurrentDepth>
|
|
203
|
-
: InternalPaths<T, Options, CurrentDepth>
|
|
204
|
-
: T extends object
|
|
205
|
-
? InternalPaths<T, Options, CurrentDepth>
|
|
206
|
-
: never;
|
|
199
|
+
: T extends object
|
|
200
|
+
? InternalPaths<Required<T>, Options, CurrentDepth>
|
|
201
|
+
: never;
|
|
207
202
|
|
|
208
203
|
type InternalPaths<T, Options extends Required<PathsOptions>, CurrentDepth extends number> =
|
|
209
|
-
|
|
210
|
-
?
|
|
211
|
-
|
|
212
|
-
?
|
|
213
|
-
:
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
? CurrentDepth extends Options['depth']
|
|
243
|
-
? _TransformedKey
|
|
244
|
-
: never
|
|
245
|
-
: never)
|
|
246
|
-
| (
|
|
247
|
-
// Recursively generate paths for the current key
|
|
248
|
-
GreaterThan<MaxDepth, CurrentDepth> extends true // Limit the depth to prevent infinite recursion
|
|
249
|
-
? `${TranformedKey}${_Paths<T[Key], Options, Sum<CurrentDepth, 1>> & (string | number)}`
|
|
250
|
-
: never
|
|
251
|
-
)
|
|
252
|
-
: never
|
|
253
|
-
: never
|
|
254
|
-
}[keyof T & (T extends UnknownArray ? number : unknown)]
|
|
204
|
+
{[Key in keyof T]: Key extends string | number // Limit `Key` to `string | number`
|
|
205
|
+
? (
|
|
206
|
+
And<Options['bracketNotation'], IsNumberLike<Key>> extends true
|
|
207
|
+
? `[${Key}]`
|
|
208
|
+
: CurrentDepth extends 0
|
|
209
|
+
// Return both `Key` and `ToString<Key>` because for number keys, like `1`, both `1` and `'1'` are valid keys.
|
|
210
|
+
? Key | ToString<Key>
|
|
211
|
+
: `.${(Key | ToString<Key>)}`
|
|
212
|
+
) extends infer TransformedKey extends string | number
|
|
213
|
+
? ((Options['leavesOnly'] extends true
|
|
214
|
+
? Options['maxRecursionDepth'] extends CurrentDepth
|
|
215
|
+
? TransformedKey
|
|
216
|
+
: IsNever<T[Key]> extends true
|
|
217
|
+
? TransformedKey
|
|
218
|
+
: T[Key] extends infer Value // For distributing `T[Key]`
|
|
219
|
+
? (Value extends readonly [] | NonRecursiveType | Exclude<MapsSetsOrArrays, UnknownArray>
|
|
220
|
+
? TransformedKey
|
|
221
|
+
: IsNever<keyof Value> extends true // Check for empty object & `unknown`, because `keyof unknown` is `never`.
|
|
222
|
+
? TransformedKey
|
|
223
|
+
: never)
|
|
224
|
+
: never // Should never happen
|
|
225
|
+
: TransformedKey
|
|
226
|
+
) extends infer _TransformedKey
|
|
227
|
+
// If `depth` is provided, the condition becomes truthy only when it matches `CurrentDepth`.
|
|
228
|
+
// Otherwise, since `depth` defaults to `number`, the condition is always truthy, returning paths at all depths.
|
|
229
|
+
? CurrentDepth extends Options['depth']
|
|
230
|
+
? _TransformedKey
|
|
231
|
+
: never
|
|
232
|
+
: never)
|
|
233
|
+
// Recursively generate paths for the current key
|
|
234
|
+
| (GreaterThan<Options['maxRecursionDepth'], CurrentDepth> extends true // Limit the depth to prevent infinite recursion
|
|
235
|
+
? `${TransformedKey}${_Paths<T[Key], Options, Sum<CurrentDepth, 1>> & (string | number)}`
|
|
236
|
+
: never)
|
|
255
237
|
: never
|
|
256
|
-
: never
|
|
238
|
+
: never
|
|
239
|
+
}[keyof T & (T extends UnknownArray ? number : unknown)];
|
|
257
240
|
|
|
258
241
|
export {};
|