type-fest 5.4.2 → 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 +2 -2
- package/source/internal/numeric.d.ts +5 -4
- package/source/is-union.d.ts +2 -1
- package/source/merge.d.ts +9 -4
- package/source/package-json.d.ts +2 -2
- package/source/paths.d.ts +45 -83
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-fest",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.4",
|
|
4
4
|
"description": "A collection of essential TypeScript types",
|
|
5
5
|
"license": "(MIT OR CC0-1.0)",
|
|
6
6
|
"repository": "sindresorhus/type-fest",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"scripts": {
|
|
28
28
|
"test:tsc": "node --max-old-space-size=6144 ./node_modules/.bin/tsc",
|
|
29
29
|
"test:tsd": "node --max-old-space-size=6144 ./node_modules/.bin/tsd",
|
|
30
|
-
"test:xo": "node --max-old-space-size=6144 ./node_modules/.bin/xo",
|
|
30
|
+
"test:xo": "node --max-old-space-size=6144 ./node_modules/.bin/xo --ignores=lint-processors/fixtures/**/*.d.ts",
|
|
31
31
|
"test:linter": "node --test",
|
|
32
32
|
"test": "run-p test:*"
|
|
33
33
|
},
|
|
@@ -2,7 +2,7 @@ import type {IsNever} from '../is-never.d.ts';
|
|
|
2
2
|
import type {Finite, NegativeInfinity, PositiveInfinity} from '../numeric.d.ts';
|
|
3
3
|
import type {UnknownArray} from '../unknown-array.d.ts';
|
|
4
4
|
import type {StringToNumber} from './string.d.ts';
|
|
5
|
-
import type {IsAnyOrNever} from './type.d.ts';
|
|
5
|
+
import type {IfNotAnyOrNever, IsAnyOrNever} from './type.d.ts';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
Returns the absolute value of a given value.
|
|
@@ -44,10 +44,11 @@ type E = IsNumberLike<'a'>;
|
|
|
44
44
|
//=> false
|
|
45
45
|
*/
|
|
46
46
|
export type IsNumberLike<N> =
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
IfNotAnyOrNever<N,
|
|
48
|
+
N extends number | `${number}`
|
|
49
49
|
? true
|
|
50
|
-
: false
|
|
50
|
+
: false,
|
|
51
|
+
boolean, false>;
|
|
51
52
|
|
|
52
53
|
/**
|
|
53
54
|
Returns the minimum number in the given union of numbers.
|
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/merge.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type {OmitIndexSignature} from './omit-index-signature.d.ts';
|
|
2
2
|
import type {PickIndexSignature} from './pick-index-signature.d.ts';
|
|
3
3
|
import type {Simplify} from './simplify.d.ts';
|
|
4
|
+
import type {If} from './if.d.ts';
|
|
5
|
+
import type {IsEqual} from './is-equal.d.ts';
|
|
4
6
|
|
|
5
7
|
// Merges two objects without worrying about index signatures.
|
|
6
8
|
type SimpleMerge<Destination, Source> = Simplify<{
|
|
@@ -47,11 +49,14 @@ Note: If you want a merge type that more accurately reflects the runtime behavio
|
|
|
47
49
|
export type Merge<Destination, Source> =
|
|
48
50
|
Destination extends unknown // For distributing `Destination`
|
|
49
51
|
? Source extends unknown // For distributing `Source`
|
|
50
|
-
?
|
|
51
|
-
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
|
|
52
|
-
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
|
|
53
|
-
>
|
|
52
|
+
? If<IsEqual<Destination, Source>, Destination, _Merge<Destination, Source>>
|
|
54
53
|
: never // Should never happen
|
|
55
54
|
: never; // Should never happen
|
|
56
55
|
|
|
56
|
+
export type _Merge<Destination, Source> =
|
|
57
|
+
Simplify<
|
|
58
|
+
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
|
|
59
|
+
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
|
|
60
|
+
>;
|
|
61
|
+
|
|
57
62
|
export {};
|
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,9 +1,10 @@
|
|
|
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
|
-
import type {Subtract} from './subtract.d.ts';
|
|
5
4
|
import type {GreaterThan} from './greater-than.d.ts';
|
|
6
5
|
import type {IsNever} from './is-never.d.ts';
|
|
6
|
+
import type {Sum} from './sum.d.ts';
|
|
7
|
+
import type {And} from './and.d.ts';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
Paths options.
|
|
@@ -190,90 +191,51 @@ open('listB.1'); // TypeError. Because listB only has one element.
|
|
|
190
191
|
*/
|
|
191
192
|
export type Paths<T, Options extends PathsOptions = {}> = _Paths<T, ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, Options>>;
|
|
192
193
|
|
|
193
|
-
type _Paths<T, Options extends Required<PathsOptions
|
|
194
|
-
T extends NonRecursiveType |
|
|
194
|
+
type _Paths<T, Options extends Required<PathsOptions>, CurrentDepth extends number = 0> =
|
|
195
|
+
T extends NonRecursiveType | Exclude<MapsSetsOrArrays, UnknownArray>
|
|
195
196
|
? never
|
|
196
197
|
: IsAny<T> extends true
|
|
197
198
|
? never
|
|
198
|
-
: T extends
|
|
199
|
-
?
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
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
|
-
? TranformedKey
|
|
237
|
-
: never)
|
|
238
|
-
: never
|
|
239
|
-
: TranformedKey
|
|
240
|
-
) extends infer _TransformedKey
|
|
241
|
-
// If `depth` is provided, the condition becomes truthy only when it reaches `0`.
|
|
242
|
-
// Otherwise, since `depth` defaults to `number`, the condition is always truthy, returning paths at all depths.
|
|
243
|
-
? 0 extends Options['depth']
|
|
244
|
-
? _TransformedKey
|
|
245
|
-
: never
|
|
246
|
-
: never)
|
|
247
|
-
| (
|
|
248
|
-
// Recursively generate paths for the current key
|
|
249
|
-
GreaterThan<MaxDepth, 0> extends true // Limit the depth to prevent infinite recursion
|
|
250
|
-
? _Paths<T[Key],
|
|
251
|
-
{
|
|
252
|
-
bracketNotation: Options['bracketNotation'];
|
|
253
|
-
maxRecursionDepth: Subtract<MaxDepth, 1>;
|
|
254
|
-
leavesOnly: Options['leavesOnly'];
|
|
255
|
-
depth: Subtract<Options['depth'], 1>;
|
|
256
|
-
}> extends infer SubPath
|
|
257
|
-
? SubPath extends string | number
|
|
258
|
-
? (
|
|
259
|
-
Options['bracketNotation'] extends true
|
|
260
|
-
? SubPath extends `[${any}]` | `[${any}]${string}`
|
|
261
|
-
? `${TranformedKey}${SubPath}` // If next node is number key like `[3]`, no need to add `.` before it.
|
|
262
|
-
: `${TranformedKey}.${SubPath}`
|
|
263
|
-
: never
|
|
264
|
-
) | (
|
|
265
|
-
Options['bracketNotation'] extends false
|
|
266
|
-
? `${TranformedKey}.${SubPath}`
|
|
267
|
-
: never
|
|
268
|
-
)
|
|
269
|
-
: never
|
|
270
|
-
: never
|
|
271
|
-
: never
|
|
272
|
-
)
|
|
273
|
-
: never
|
|
274
|
-
: never
|
|
275
|
-
}[keyof T & (T extends UnknownArray ? number : unknown)]
|
|
199
|
+
: T extends object
|
|
200
|
+
? InternalPaths<Required<T>, Options, CurrentDepth>
|
|
201
|
+
: never;
|
|
202
|
+
|
|
203
|
+
type InternalPaths<T, Options extends Required<PathsOptions>, CurrentDepth extends number> =
|
|
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)
|
|
276
237
|
: never
|
|
277
|
-
: never
|
|
238
|
+
: never
|
|
239
|
+
}[keyof T & (T extends UnknownArray ? number : unknown)];
|
|
278
240
|
|
|
279
241
|
export {};
|