type-fest 4.10.1 → 4.10.3
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
CHANGED
package/source/internal.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type {Primitive} from './primitive';
|
|
|
2
2
|
import type {Simplify} from './simplify';
|
|
3
3
|
import type {Trim} from './trim';
|
|
4
4
|
import type {IsAny} from './is-any';
|
|
5
|
+
import type {IsLiteral} from './is-literal';
|
|
5
6
|
import type {UnknownRecord} from './unknown-record';
|
|
6
7
|
import type {IsNever} from './is-never';
|
|
7
8
|
import type {UnknownArray} from './unknown-array';
|
|
@@ -357,6 +358,11 @@ IsPrimitive<Object>
|
|
|
357
358
|
*/
|
|
358
359
|
export type IsPrimitive<T> = [T] extends [Primitive] ? true : false;
|
|
359
360
|
|
|
361
|
+
/**
|
|
362
|
+
Utility type to retrieve only literal keys from type.
|
|
363
|
+
*/
|
|
364
|
+
export type LiteralKeyOf<T> = keyof {[K in keyof T as IsLiteral<K> extends true ? K : never]-?: never};
|
|
365
|
+
|
|
360
366
|
/**
|
|
361
367
|
Returns the static, fixed-length portion of the given array, excluding variable-length parts.
|
|
362
368
|
|
package/source/merge-deep.d.ts
CHANGED
|
@@ -63,6 +63,9 @@ type MergeDeepRecord<
|
|
|
63
63
|
> = DoMergeDeepRecord<OmitIndexSignature<Destination>, OmitIndexSignature<Source>, Options>
|
|
64
64
|
& Merge<PickIndexSignature<Destination>, PickIndexSignature<Source>>;
|
|
65
65
|
|
|
66
|
+
// Helper to avoid computing ArrayTail twice.
|
|
67
|
+
type PickRestTypeHelper<Tail extends UnknownArrayOrTuple, Type> = Tail extends [] ? Type : PickRestType<Tail>;
|
|
68
|
+
|
|
66
69
|
/**
|
|
67
70
|
Pick the rest type.
|
|
68
71
|
|
|
@@ -76,9 +79,18 @@ type Rest5 = PickRestType<string[]>; // => string[]
|
|
|
76
79
|
```
|
|
77
80
|
*/
|
|
78
81
|
type PickRestType<Type extends UnknownArrayOrTuple> = number extends Type['length']
|
|
79
|
-
? ArrayTail<Type
|
|
82
|
+
? PickRestTypeHelper<ArrayTail<Type>, Type>
|
|
80
83
|
: [];
|
|
81
84
|
|
|
85
|
+
// Helper to avoid computing ArrayTail twice.
|
|
86
|
+
type OmitRestTypeHelper<
|
|
87
|
+
Tail extends UnknownArrayOrTuple,
|
|
88
|
+
Type extends UnknownArrayOrTuple,
|
|
89
|
+
Result extends UnknownArrayOrTuple = [],
|
|
90
|
+
> = Tail extends []
|
|
91
|
+
? Result
|
|
92
|
+
: OmitRestType<Tail, [...Result, FirstArrayElement<Type>]>;
|
|
93
|
+
|
|
82
94
|
/**
|
|
83
95
|
Omit the rest type.
|
|
84
96
|
|
|
@@ -93,7 +105,7 @@ type Tuple6 = OmitRestType<string[]>; // => []
|
|
|
93
105
|
```
|
|
94
106
|
*/
|
|
95
107
|
type OmitRestType<Type extends UnknownArrayOrTuple, Result extends UnknownArrayOrTuple = []> = number extends Type['length']
|
|
96
|
-
?
|
|
108
|
+
? OmitRestTypeHelper<ArrayTail<Type>, Type, Result>
|
|
97
109
|
: Type;
|
|
98
110
|
|
|
99
111
|
// Utility to avoid picking two times the type.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {IfUnknown} from './if-unknown';
|
|
2
|
+
import type {BuiltIns, LiteralKeyOf} from './internal';
|
|
2
3
|
import type {Merge} from './merge';
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -47,8 +48,8 @@ const testSettings: PartialOnUndefinedDeep<Settings> = {
|
|
|
47
48
|
@category Object
|
|
48
49
|
*/
|
|
49
50
|
export type PartialOnUndefinedDeep<T, Options extends PartialOnUndefinedDeepOptions = {}> = T extends Record<any, any> | undefined
|
|
50
|
-
? {[KeyType in keyof T as undefined extends T[KeyType] ? KeyType : never]?: PartialOnUndefinedDeepValue<T[KeyType], Options>} extends infer U // Make a partial type with all value types accepting undefined (and set them optional)
|
|
51
|
-
? Merge<{[KeyType in keyof T as KeyType extends
|
|
51
|
+
? {[KeyType in keyof T as undefined extends T[KeyType] ? IfUnknown<T[KeyType], never, KeyType> : never]?: PartialOnUndefinedDeepValue<T[KeyType], Options>} extends infer U // Make a partial type with all value types accepting undefined (and set them optional)
|
|
52
|
+
? Merge<{[KeyType in keyof T as KeyType extends LiteralKeyOf<U> ? never : KeyType]: PartialOnUndefinedDeepValue<T[KeyType], Options>}, U> // Join all remaining keys not treated in U
|
|
52
53
|
: never // Should not happen
|
|
53
54
|
: T;
|
|
54
55
|
|