type-fest 4.40.0 → 4.40.1

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.40.0",
3
+ "version": "4.40.1",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
@@ -68,12 +68,11 @@ type _CamelCasedPropertiesDeep<
68
68
  ? CamelCasedPropertiesArrayDeep<Value, Options>
69
69
  : Value extends Set<infer U>
70
70
  ? Set<_CamelCasedPropertiesDeep<U, Options>>
71
- : {
72
- [K in keyof Value as CamelCase<K, Options>]: _CamelCasedPropertiesDeep<
73
- Value[K],
74
- Options
75
- >;
76
- };
71
+ : Value extends object
72
+ ? {
73
+ [K in keyof Value as CamelCase<K, Options>]: _CamelCasedPropertiesDeep<Value[K], Options>;
74
+ }
75
+ : Value;
77
76
 
78
77
  // This is a copy of DelimiterCasedPropertiesArrayDeep (see: delimiter-cased-properties-deep.d.ts).
79
78
  // These types should be kept in sync.
@@ -72,13 +72,13 @@ type _DelimiterCasedPropertiesDeep<
72
72
  : Value extends UnknownArray
73
73
  ? DelimiterCasedPropertiesArrayDeep<Value, Delimiter, Options>
74
74
  : Value extends Set<infer U>
75
- ? Set<_DelimiterCasedPropertiesDeep<U, Delimiter, Options>> : {
76
- [K in keyof Value as DelimiterCase<
77
- K,
78
- Delimiter,
79
- Options
80
- >]: _DelimiterCasedPropertiesDeep<Value[K], Delimiter, Options>;
81
- };
75
+ ? Set<_DelimiterCasedPropertiesDeep<U, Delimiter, Options>>
76
+ : Value extends object
77
+ ? {
78
+ [K in keyof Value as DelimiterCase<K, Delimiter, Options>]:
79
+ _DelimiterCasedPropertiesDeep<Value[K], Delimiter, Options>
80
+ }
81
+ : Value;
82
82
 
83
83
  // This is a copy of CamelCasedPropertiesArrayDeep (see: camel-cased-properties-deep.d.ts).
84
84
  // These types should be kept in sync.
@@ -1,4 +1,5 @@
1
1
  import type {ApplyDefaultOptions, BuiltIns} from './internal';
2
+ import type {IsNever} from './is-never';
2
3
 
3
4
  /**
4
5
  @see {@link PartialDeep}
@@ -95,27 +96,29 @@ const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
95
96
  export type PartialDeep<T, Options extends PartialDeepOptions = {}> =
96
97
  _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
97
98
 
98
- type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
99
+ type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown))
99
100
  ? T
100
- : T extends Map<infer KeyType, infer ValueType>
101
- ? PartialMapDeep<KeyType, ValueType, Options>
102
- : T extends Set<infer ItemType>
103
- ? PartialSetDeep<ItemType, Options>
104
- : T extends ReadonlyMap<infer KeyType, infer ValueType>
105
- ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
106
- : T extends ReadonlySet<infer ItemType>
107
- ? PartialReadonlySetDeep<ItemType, Options>
108
- : T extends object
109
- ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
110
- ? Options['recurseIntoArrays'] extends true
111
- ? ItemType[] extends T // Test for arrays (non-tuples) specifically
112
- ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
113
- ? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
114
- : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
115
- : PartialObjectDeep<T, Options> // Tuples behave properly
116
- : T // If they don't opt into array testing, just use the original type
117
- : PartialObjectDeep<T, Options>
118
- : unknown;
101
+ : IsNever<keyof T> extends true // For functions with no properties
102
+ ? T
103
+ : T extends Map<infer KeyType, infer ValueType>
104
+ ? PartialMapDeep<KeyType, ValueType, Options>
105
+ : T extends Set<infer ItemType>
106
+ ? PartialSetDeep<ItemType, Options>
107
+ : T extends ReadonlyMap<infer KeyType, infer ValueType>
108
+ ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
109
+ : T extends ReadonlySet<infer ItemType>
110
+ ? PartialReadonlySetDeep<ItemType, Options>
111
+ : T extends object
112
+ ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
113
+ ? Options['recurseIntoArrays'] extends true
114
+ ? ItemType[] extends T // Test for arrays (non-tuples) specifically
115
+ ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
116
+ ? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
117
+ : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
118
+ : PartialObjectDeep<T, Options> // Tuples behave properly
119
+ : T // If they don't opt into array testing, just use the original type
120
+ : PartialObjectDeep<T, Options>
121
+ : unknown;
119
122
 
120
123
  /**
121
124
  Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
@@ -140,6 +143,9 @@ type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {
140
143
  /**
141
144
  Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
142
145
  */
143
- type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = {
144
- [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
145
- };
146
+ type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> =
147
+ (ObjectType extends (...arguments_: any) => unknown
148
+ ? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType>
149
+ : {}) & ({
150
+ [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
151
+ });
@@ -54,6 +54,9 @@ type _PascalCasedPropertiesDeep<Value, Options extends Required<CamelCaseOptions
54
54
  : Value extends Array<infer U>
55
55
  ? Array<_PascalCasedPropertiesDeep<U, Options>>
56
56
  : Value extends Set<infer U>
57
- ? Set<_PascalCasedPropertiesDeep<U, Options>> : {
58
- [K in keyof Value as PascalCase<K, Options>]: _PascalCasedPropertiesDeep<Value[K], Options>;
59
- };
57
+ ? Set<_PascalCasedPropertiesDeep<U, Options>>
58
+ : Value extends object
59
+ ? {
60
+ [K in keyof Value as PascalCase<K, Options>]: _PascalCasedPropertiesDeep<Value[K], Options>;
61
+ }
62
+ : Value;