type-fest 4.18.1 → 4.18.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "4.18.1",
3
+ "version": "4.18.3",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
@@ -1,4 +1,5 @@
1
1
  import type {CamelCase, CamelCaseOptions} from './camel-case';
2
+ import type {UnknownArray} from './unknown-array';
2
3
 
3
4
  /**
4
5
  Convert object properties to camel case recursively.
@@ -44,11 +45,43 @@ const result: CamelCasedPropertiesDeep<UserWithFriends> = {
44
45
  @category Template literal
45
46
  @category Object
46
47
  */
47
- export type CamelCasedPropertiesDeep<Value, Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true}> = Value extends Function
48
+ export type CamelCasedPropertiesDeep<
49
+ Value,
50
+ Options extends CamelCaseOptions = {preserveConsecutiveUppercase: true},
51
+ > = Value extends Function
48
52
  ? Value
49
- : Value extends Array<infer U>
50
- ? Array<CamelCasedPropertiesDeep<U, Options>>
53
+ : Value extends UnknownArray
54
+ ? CamelCasedPropertiesArrayDeep<Value>
51
55
  : Value extends Set<infer U>
52
- ? Set<CamelCasedPropertiesDeep<U, Options>> : {
53
- [K in keyof Value as CamelCase<K, Options>]: CamelCasedPropertiesDeep<Value[K], Options>;
56
+ ? Set<CamelCasedPropertiesDeep<U, Options>>
57
+ : {
58
+ [K in keyof Value as CamelCase<K, Options>]: CamelCasedPropertiesDeep<
59
+ Value[K],
60
+ Options
61
+ >;
54
62
  };
63
+
64
+ // This is a copy of DelimiterCasedPropertiesArrayDeep (see: delimiter-cased-properties-deep.d.ts).
65
+ // These types should be kept in sync.
66
+ type CamelCasedPropertiesArrayDeep<Value extends UnknownArray> =
67
+ Value extends []
68
+ ? []
69
+ : // Tailing spread array
70
+ Value extends [infer U, ...infer V]
71
+ ? [CamelCasedPropertiesDeep<U>, ...CamelCasedPropertiesDeep<V>]
72
+ : Value extends readonly [infer U, ...infer V]
73
+ ? readonly [CamelCasedPropertiesDeep<U>, ...CamelCasedPropertiesDeep<V>]
74
+ : // Leading spread array
75
+ Value extends readonly [...infer U, infer V]
76
+ ? [...CamelCasedPropertiesDeep<U>, CamelCasedPropertiesDeep<V>]
77
+ : Value extends readonly [...infer U, infer V]
78
+ ? readonly [
79
+ ...CamelCasedPropertiesDeep<U>,
80
+ CamelCasedPropertiesDeep<V>,
81
+ ]
82
+ : // Array
83
+ Value extends Array<infer U>
84
+ ? Array<CamelCasedPropertiesDeep<U>>
85
+ : Value extends ReadonlyArray<infer U>
86
+ ? ReadonlyArray<CamelCasedPropertiesDeep<U>>
87
+ : never;
@@ -1,3 +1,5 @@
1
+ import type {IfNever} from './if-never';
2
+
1
3
  /**
2
4
  Extract the keys from a type where the value type of the key extends the given `Condition`.
3
5
 
@@ -36,10 +38,10 @@ export type ConditionalKeys<Base, Condition> =
36
38
  [Key in keyof Base]-?:
37
39
  // Pick only keys with types extending the given `Condition` type.
38
40
  Base[Key] extends Condition
39
- // Retain this key since the condition passes.
40
- ? Key
41
+ // Retain this key
42
+ // If the value for the key extends never, only include it if `Condition` also extends never
43
+ ? IfNever<Base[Key], IfNever<Condition, Key, never>, Key>
41
44
  // Discard this key since the condition fails.
42
45
  : never;
43
-
44
46
  // Convert the produced object into a union type of the keys which passed the conditional test.
45
47
  }[keyof Base];
@@ -61,6 +61,8 @@ export type DelimiterCasedPropertiesDeep<
61
61
  >]: DelimiterCasedPropertiesDeep<Value[K], Delimiter>;
62
62
  };
63
63
 
64
+ // This is a copy of CamelCasedPropertiesArrayDeep (see: camel-cased-properties-deep.d.ts).
65
+ // These types should be kept in sync.
64
66
  type DelimiterCasedPropertiesArrayDeep<Value extends UnknownArray, Delimiter extends string> =
65
67
  Value extends []
66
68
  ? []