type-fest 4.41.0 → 5.0.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.
Files changed (156) hide show
  1. package/index.d.ts +174 -153
  2. package/package.json +20 -44
  3. package/readme.md +45 -68
  4. package/source/all-extend.d.ts +115 -0
  5. package/source/all-union-fields.d.ts +12 -12
  6. package/source/and.d.ts +60 -8
  7. package/source/array-slice.d.ts +11 -11
  8. package/source/array-splice.d.ts +4 -4
  9. package/source/array-tail.d.ts +40 -48
  10. package/source/arrayable.d.ts +2 -2
  11. package/source/asyncify.d.ts +1 -1
  12. package/source/basic.d.ts +1 -33
  13. package/source/camel-case.d.ts +6 -6
  14. package/source/camel-cased-properties-deep.d.ts +7 -7
  15. package/source/camel-cased-properties.d.ts +4 -4
  16. package/source/characters.d.ts +60 -0
  17. package/source/conditional-except.d.ts +4 -4
  18. package/source/conditional-keys.d.ts +33 -19
  19. package/source/conditional-pick-deep.d.ts +9 -9
  20. package/source/conditional-pick.d.ts +3 -3
  21. package/source/conditional-simplify-deep.d.ts +71 -0
  22. package/source/conditional-simplify.d.ts +36 -20
  23. package/source/delimiter-case.d.ts +9 -12
  24. package/source/delimiter-cased-properties-deep.d.ts +4 -4
  25. package/source/delimiter-cased-properties.d.ts +3 -3
  26. package/source/distributed-omit.d.ts +1 -1
  27. package/source/distributed-pick.d.ts +1 -1
  28. package/source/enforce-optional.d.ts +1 -1
  29. package/source/entries.d.ts +1 -1
  30. package/source/exact.d.ts +6 -6
  31. package/source/except.d.ts +2 -2
  32. package/source/exclude-strict.d.ts +45 -0
  33. package/source/extends-strict.d.ts +42 -0
  34. package/source/extract-strict.d.ts +45 -0
  35. package/source/find-global-type.d.ts +1 -1
  36. package/source/fixed-length-array.d.ts +2 -2
  37. package/source/get.d.ts +15 -14
  38. package/source/globals/index.d.ts +1 -0
  39. package/source/{observable-like.d.ts → globals/observable-like.d.ts} +10 -0
  40. package/source/greater-than-or-equal.d.ts +1 -1
  41. package/source/greater-than.d.ts +9 -9
  42. package/source/has-optional-keys.d.ts +1 -1
  43. package/source/has-readonly-keys.d.ts +1 -1
  44. package/source/has-required-keys.d.ts +1 -1
  45. package/source/has-writable-keys.d.ts +1 -1
  46. package/source/if-any.d.ts +3 -1
  47. package/source/if-empty-object.d.ts +3 -1
  48. package/source/if-never.d.ts +3 -1
  49. package/source/if-null.d.ts +3 -1
  50. package/source/if-unknown.d.ts +3 -1
  51. package/source/if.d.ts +65 -0
  52. package/source/includes.d.ts +1 -1
  53. package/source/int-closed-range.d.ts +2 -2
  54. package/source/int-range.d.ts +6 -4
  55. package/source/internal/array.d.ts +54 -22
  56. package/source/internal/characters.d.ts +0 -4
  57. package/source/internal/index.d.ts +8 -8
  58. package/source/internal/keys.d.ts +24 -23
  59. package/source/internal/numeric.d.ts +45 -15
  60. package/source/internal/object.d.ts +58 -29
  61. package/source/internal/string.d.ts +4 -14
  62. package/source/internal/tuple.d.ts +4 -4
  63. package/source/internal/type.d.ts +34 -43
  64. package/source/is-any.d.ts +0 -4
  65. package/source/is-float.d.ts +1 -1
  66. package/source/is-integer.d.ts +4 -4
  67. package/source/is-literal.d.ts +44 -28
  68. package/source/is-lowercase.d.ts +36 -0
  69. package/source/is-nullable.d.ts +28 -0
  70. package/source/is-optional-key-of.d.ts +49 -0
  71. package/source/is-optional.d.ts +26 -0
  72. package/source/is-readonly-key-of.d.ts +53 -0
  73. package/source/is-required-key-of.d.ts +49 -0
  74. package/source/is-tuple.d.ts +15 -14
  75. package/source/is-undefined.d.ts +20 -0
  76. package/source/is-union.d.ts +37 -0
  77. package/source/is-unknown.d.ts +1 -1
  78. package/source/is-uppercase.d.ts +36 -0
  79. package/source/is-writable-key-of.d.ts +49 -0
  80. package/source/json-value.d.ts +31 -0
  81. package/source/jsonifiable.d.ts +1 -1
  82. package/source/jsonify.d.ts +18 -14
  83. package/source/kebab-case.d.ts +3 -3
  84. package/source/kebab-cased-properties-deep.d.ts +4 -4
  85. package/source/kebab-cased-properties.d.ts +4 -4
  86. package/source/{string-key-of.d.ts → key-as-string.d.ts} +5 -5
  87. package/source/keys-of-union.d.ts +1 -1
  88. package/source/less-than-or-equal.d.ts +1 -1
  89. package/source/less-than.d.ts +1 -1
  90. package/source/literal-to-primitive-deep.d.ts +2 -2
  91. package/source/literal-union.d.ts +1 -1
  92. package/source/merge-deep.d.ts +43 -34
  93. package/source/merge.d.ts +5 -5
  94. package/source/multidimensional-array.d.ts +2 -2
  95. package/source/multidimensional-readonly-array.d.ts +2 -2
  96. package/source/non-empty-object.d.ts +2 -2
  97. package/source/numeric.d.ts +4 -4
  98. package/source/omit-deep.d.ts +11 -11
  99. package/source/opaque.d.ts +1 -1
  100. package/source/optional-keys-of.d.ts +10 -5
  101. package/source/or.d.ts +67 -7
  102. package/source/override-properties.d.ts +1 -1
  103. package/source/package-json.d.ts +78 -78
  104. package/source/partial-deep.d.ts +22 -21
  105. package/source/partial-on-undefined-deep.d.ts +5 -4
  106. package/source/pascal-case.d.ts +13 -6
  107. package/source/pascal-cased-properties-deep.d.ts +11 -3
  108. package/source/pascal-cased-properties.d.ts +7 -3
  109. package/source/paths.d.ts +42 -39
  110. package/source/pick-deep.d.ts +6 -6
  111. package/source/readonly-deep.d.ts +2 -2
  112. package/source/readonly-keys-of.d.ts +10 -4
  113. package/source/remove-prefix.d.ts +128 -0
  114. package/source/replace.d.ts +1 -1
  115. package/source/require-all-or-none.d.ts +8 -7
  116. package/source/require-at-least-one.d.ts +10 -9
  117. package/source/require-exactly-one.d.ts +8 -7
  118. package/source/require-one-or-none.d.ts +9 -8
  119. package/source/required-deep.d.ts +26 -32
  120. package/source/required-keys-of.d.ts +4 -4
  121. package/source/schema.d.ts +74 -74
  122. package/source/screaming-snake-case.d.ts +4 -4
  123. package/source/set-field-type.d.ts +2 -2
  124. package/source/set-non-nullable-deep.d.ts +6 -6
  125. package/source/set-optional.d.ts +11 -5
  126. package/source/set-parameter-type.d.ts +7 -7
  127. package/source/set-readonly.d.ts +12 -9
  128. package/source/set-required-deep.d.ts +12 -12
  129. package/source/set-required.d.ts +15 -8
  130. package/source/set-return-type.d.ts +1 -1
  131. package/source/shared-union-fields-deep.d.ts +10 -10
  132. package/source/shared-union-fields.d.ts +5 -4
  133. package/source/simplify-deep.d.ts +3 -3
  134. package/source/single-key-object.d.ts +4 -3
  135. package/source/snake-case.d.ts +3 -3
  136. package/source/snake-cased-properties-deep.d.ts +4 -4
  137. package/source/snake-cased-properties.d.ts +4 -4
  138. package/source/split.d.ts +9 -9
  139. package/source/spread.d.ts +3 -3
  140. package/source/string-repeat.d.ts +2 -2
  141. package/source/string-slice.d.ts +3 -3
  142. package/source/structured-cloneable.d.ts +25 -25
  143. package/source/subtract.d.ts +3 -3
  144. package/source/sum.d.ts +3 -3
  145. package/source/tagged-union.d.ts +1 -1
  146. package/source/tagged.d.ts +3 -1
  147. package/source/trim.d.ts +1 -1
  148. package/source/tsconfig-json.d.ts +2 -1
  149. package/source/tuple-to-object.d.ts +5 -4
  150. package/source/undefined-on-partial-deep.d.ts +1 -1
  151. package/source/union-to-tuple.d.ts +2 -2
  152. package/source/value-of.d.ts +1 -1
  153. package/source/words.d.ts +5 -5
  154. package/source/writable-deep.d.ts +1 -1
  155. package/source/writable-keys-of.d.ts +5 -6
  156. package/source/writable.d.ts +4 -4
@@ -1,3 +1,49 @@
1
+ import type {ApplyDefaultOptions} from './internal/object.d.ts';
2
+ import type {IfNotAnyOrNever, NonRecursiveType} from './internal/type.d.ts';
3
+ import type {OptionalKeysOf} from './optional-keys-of.d.ts';
4
+ import type {Simplify} from './simplify.d.ts';
5
+ import type {UnknownArray} from './unknown-array.d.ts';
6
+
7
+ /**
8
+ @see {@link Schema}
9
+ */
10
+ export type SchemaOptions = {
11
+ /**
12
+ By default, this affects elements in array and tuple types. You can change this by passing `{recurseIntoArrays: false}` as the third type argument:
13
+ - If `recurseIntoArrays` is set to `true` (default), array elements will be recursively processed as well.
14
+ - If `recurseIntoArrays` is set to `false`, arrays will not be recursively processed, and the entire array will be replaced with the given value type.
15
+
16
+ @example
17
+ ```
18
+ import type {Schema} from 'type-fest';
19
+
20
+ type Participants = {
21
+ attendees: string[];
22
+ speakers: string[];
23
+ };
24
+
25
+ type ParticipantsWithMetadata = Schema<Participants, {id: number; name: string}, {recurseIntoArrays: true}>;
26
+ //=> {
27
+ // attendees: Array<{id: number; name: string}>;
28
+ // speakers: Array<{id: number; name: string}>;
29
+ // };
30
+
31
+ type ParticipantsCount = Schema<Participants, number, {recurseIntoArrays: false}>;
32
+ //=> {
33
+ // attendees: number;
34
+ // speakers: number;
35
+ // };
36
+ ```
37
+
38
+ @default true
39
+ */
40
+ recurseIntoArrays?: boolean;
41
+ };
42
+
43
+ type DefaultSchemaOptions = {
44
+ recurseIntoArrays: true;
45
+ };
46
+
1
47
  /**
2
48
  Create a deep version of another object type where property values are recursively replaced into a given value type.
3
49
 
@@ -10,7 +56,7 @@ Use-cases:
10
56
  ```
11
57
  import type {Schema} from 'type-fest';
12
58
 
13
- interface User {
59
+ type User = {
14
60
  id: string;
15
61
  name: {
16
62
  firstname: string;
@@ -19,8 +65,8 @@ interface User {
19
65
  created: Date;
20
66
  active: boolean;
21
67
  passwordHash: string;
22
- attributes: ['Foo', 'Bar']
23
- }
68
+ location: [latitude: number, longitude: number];
69
+ };
24
70
 
25
71
  type UserMask = Schema<User, 'mask' | 'hide' | 'show'>;
26
72
 
@@ -33,82 +79,36 @@ const userMaskSettings: UserMask = {
33
79
  created: 'show',
34
80
  active: 'show',
35
81
  passwordHash: 'hide',
36
- attributes: ['mask', 'show']
37
- }
82
+ location: ['hide', 'hide'],
83
+ };
38
84
  ```
39
85
 
86
+ @see {@link SchemaOptions}
87
+
40
88
  @category Object
41
89
  */
42
- export type Schema<ObjectType, ValueType, Options extends SchemaOptions = {}> = ObjectType extends string
43
- ? ValueType
44
- : ObjectType extends Map<unknown, unknown>
45
- ? ValueType
46
- : ObjectType extends Set<unknown>
47
- ? ValueType
48
- : ObjectType extends ReadonlyMap<unknown, unknown>
49
- ? ValueType
50
- : ObjectType extends ReadonlySet<unknown>
51
- ? ValueType
52
- : ObjectType extends Array<infer U>
53
- ? Options['recurseIntoArrays'] extends false | undefined
54
- ? ValueType
55
- : Array<Schema<U, ValueType>>
56
- : ObjectType extends (...arguments_: unknown[]) => unknown
57
- ? ValueType
58
- : ObjectType extends Date
59
- ? ValueType
60
- : ObjectType extends Function
61
- ? ValueType
62
- : ObjectType extends RegExp
63
- ? ValueType
64
- : ObjectType extends object
65
- ? SchemaObject<ObjectType, ValueType, Options>
66
- : ValueType;
90
+ export type Schema<Type, Value, Options extends SchemaOptions = {}> =
91
+ IfNotAnyOrNever<Type,
92
+ _Schema<Type, Value, ApplyDefaultOptions<SchemaOptions, DefaultSchemaOptions, Options>>,
93
+ Value, Value>;
67
94
 
68
- /**
69
- Same as `Schema`, but accepts only `object`s as inputs. Internal helper for `Schema`.
70
- */
71
- type SchemaObject<
72
- ObjectType extends object,
73
- K,
74
- Options extends SchemaOptions,
75
- > = {
76
- [KeyType in keyof ObjectType]: ObjectType[KeyType] extends
77
- | readonly unknown[]
78
- | unknown[]
79
- ? Options['recurseIntoArrays'] extends false | undefined
80
- ? K
81
- : Schema<ObjectType[KeyType], K, Options>
82
- : Schema<ObjectType[KeyType], K, Options> | K;
83
- };
95
+ type _Schema<Type, Value, Options extends Required<SchemaOptions>> =
96
+ Type extends NonRecursiveType | Map<unknown, unknown> | Set<unknown> | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>
97
+ ? Value
98
+ : Type extends UnknownArray
99
+ ? Options['recurseIntoArrays'] extends false
100
+ ? Value
101
+ : SchemaHelper<Type, Value, Options>
102
+ : SchemaHelper<Type, Value, Options>;
84
103
 
85
104
  /**
86
- @see Schema
87
- */
88
- export type SchemaOptions = {
89
- /**
90
- By default, this affects elements in array and tuple types. You can change this by passing `{recurseIntoArrays: false}` as the third type argument:
91
- - If `recurseIntoArrays` is set to `true` (default), array elements will be recursively processed as well.
92
- - If `recurseIntoArrays` is set to `false`, arrays will not be recursively processed, and the entire array will be replaced with the given value type.
93
-
94
- @example
95
- ```
96
- type UserMask = Schema<User, 'mask' | 'hide' | 'show', {recurseIntoArrays: false}>;
97
-
98
- const userMaskSettings: UserMask = {
99
- id: 'show',
100
- name: {
101
- firstname: 'show',
102
- lastname: 'mask',
103
- },
104
- created: 'show',
105
- active: 'show',
106
- passwordHash: 'hide',
107
- attributes: 'hide'
108
- }
109
- ```
105
+ Internal helper for {@link _Schema}.
110
106
 
111
- @default true
112
- */
113
- readonly recurseIntoArrays?: boolean | undefined;
114
- };
107
+ Recursively transforms the value of each property in objects and arrays.
108
+ */
109
+ type SchemaHelper<Type, Value, Options extends Required<SchemaOptions>> = Simplify<{
110
+ [Key in keyof Type]: _Schema<
111
+ Key extends OptionalKeysOf<Type & object> ? Exclude<Type[Key], undefined> : Type[Key], // Remove `| undefined` when accessing optional properties
112
+ Value,
113
+ Options>
114
+ }>;
@@ -1,7 +1,7 @@
1
- import type {DefaultDelimiterCaseOptions} from './delimiter-case';
2
- import type {ApplyDefaultOptions} from './internal';
3
- import type {SnakeCase} from './snake-case';
4
- import type {WordsOptions} from './words';
1
+ import type {DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
2
+ import type {ApplyDefaultOptions} from './internal/index.d.ts';
3
+ import type {SnakeCase} from './snake-case.d.ts';
4
+ import type {WordsOptions} from './words.d.ts';
5
5
 
6
6
  /**
7
7
  Convert a string literal to screaming-snake-case.
@@ -1,5 +1,5 @@
1
- import type {ApplyDefaultOptions} from './internal';
2
- import type {Simplify} from './simplify';
1
+ import type {ApplyDefaultOptions} from './internal/index.d.ts';
2
+ import type {Simplify} from './simplify.d.ts';
3
3
 
4
4
  type SetFieldTypeOptions = {
5
5
  /**
@@ -1,9 +1,9 @@
1
- import type {NonRecursiveType, StringToNumber} from './internal';
2
- import type {Paths} from './paths';
3
- import type {SetNonNullable} from './set-non-nullable';
4
- import type {Simplify} from './simplify';
5
- import type {UnionToTuple} from './union-to-tuple';
6
- import type {UnknownArray} from './unknown-array';
1
+ import type {NonRecursiveType, StringToNumber} from './internal/index.d.ts';
2
+ import type {Paths} from './paths.d.ts';
3
+ import type {SetNonNullable} from './set-non-nullable.d.ts';
4
+ import type {Simplify} from './simplify.d.ts';
5
+ import type {UnionToTuple} from './union-to-tuple.d.ts';
6
+ import type {UnknownArray} from './unknown-array.d.ts';
7
7
 
8
8
  /**
9
9
  Create a type that makes the specified keys non-nullable (removes `null` and `undefined`), supports deeply nested key paths, and leaves all other keys unchanged.
@@ -1,6 +1,6 @@
1
- import type {Except} from './except';
2
- import type {HomomorphicPick} from './internal';
3
- import type {Simplify} from './simplify';
1
+ import type {Except} from './except.d.ts';
2
+ import type {HomomorphicPick} from './internal/index.d.ts';
3
+ import type {Simplify} from './simplify.d.ts';
4
4
 
5
5
  /**
6
6
  Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the `SetRequired` type.
@@ -28,11 +28,17 @@ type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
28
28
  @category Object
29
29
  */
30
30
  export type SetOptional<BaseType, Keys extends keyof BaseType> =
31
+ (BaseType extends (...arguments_: never) => any
32
+ ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType>
33
+ : unknown)
34
+ & _SetOptional<BaseType, Keys>;
35
+
36
+ type _SetOptional<BaseType, Keys extends keyof BaseType> =
31
37
  BaseType extends unknown // To distribute `BaseType` when it's a union type.
32
38
  ? Simplify<
33
39
  // Pick just the keys that are readonly from the base type.
34
- Except<BaseType, Keys> &
40
+ Except<BaseType, Keys> &
35
41
  // Pick the keys that should be mutable from the base type and make them mutable.
36
- Partial<HomomorphicPick<BaseType, Keys>>
42
+ Partial<HomomorphicPick<BaseType, Keys>>
37
43
  >
38
44
  : never;
@@ -1,6 +1,6 @@
1
- import type {IsUnknown} from './is-unknown';
2
- import type {StaticPartOfArray, VariablePartOfArray} from './internal';
3
- import type {UnknownArray} from './unknown-array';
1
+ import type {IsUnknown} from './is-unknown.d.ts';
2
+ import type {StaticPartOfArray, VariablePartOfArray} from './internal/index.d.ts';
3
+ import type {UnknownArray} from './unknown-array.d.ts';
4
4
 
5
5
  /**
6
6
  Create an array that replaces the given `TArray`'s elements with the given `TObject`'s values at the given indices.
@@ -78,7 +78,7 @@ Use-case:
78
78
  ```
79
79
  import type {SetParameterType} from 'type-fest';
80
80
 
81
- type HandleMessage = (data: Data, message: string, ...arguments: any[]) => void;
81
+ type HandleMessage = (data: Data, message: string, ...arguments_: any[]) => void;
82
82
 
83
83
  type HandleOk = SetParameterType<HandleMessage, {0: SuccessData, 1: 'ok'}>;
84
84
  //=> type HandleOk = (data: SuccessData, message: 'ok') => void;
@@ -94,12 +94,12 @@ type HandleWarn = SetParameterType<HandleMessage, {1: 'warn'}>;
94
94
  // Change rest parameter type.
95
95
 
96
96
  // Way 1: Input full parameter type.
97
- type HandleLog = SetParameterType<HandleMessage, [data: Data, message: 'log', ...arguments: string[]]>;
98
- //=> type HandleLog = (data: Data, message: 'log', ...arguments: string[]) => void;
97
+ type HandleLog = SetParameterType<HandleMessage, [data: Data, message: 'log', ...arguments_: string[]]>;
98
+ //=> type HandleLog = (data: Data, message: 'log', ...arguments_: string[]) => void;
99
99
 
100
100
  // Way 2: Input rest parameter type by Object index.
101
101
  type HandleLog2 = SetParameterType<HandleMessage, {2: string}>;
102
- //=> type HandleLog2 = (data: Data, message: string, ...arguments: string[]) => void;
102
+ //=> type HandleLog2 = (data: Data, message: string, ...arguments_: string[]) => void;
103
103
  ```
104
104
 
105
105
  @category Function
@@ -1,6 +1,6 @@
1
- import type {Except} from './except';
2
- import type {HomomorphicPick} from './internal';
3
- import type {Simplify} from './simplify';
1
+ import type {Except} from './except.d.ts';
2
+ import type {HomomorphicPick} from './internal/index.d.ts';
3
+ import type {Simplify} from './simplify.d.ts';
4
4
 
5
5
  /**
6
6
  Create a type that makes the given keys readonly. The remaining keys are kept as is.
@@ -28,12 +28,15 @@ type SomeReadonly = SetReadonly<Foo, 'b' | 'c'>;
28
28
  @category Object
29
29
  */
30
30
  export type SetReadonly<BaseType, Keys extends keyof BaseType> =
31
- // `extends unknown` is always going to be the case and is used to convert any
32
- // union into a [distributive conditional
33
- // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
34
- BaseType extends unknown
31
+ (BaseType extends (...arguments_: never) => any
32
+ ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType>
33
+ : unknown)
34
+ & _SetReadonly<BaseType, Keys>;
35
+
36
+ export type _SetReadonly<BaseType, Keys extends keyof BaseType> =
37
+ BaseType extends unknown // To distribute `BaseType` when it's a union type.
35
38
  ? Simplify<
36
- Except<BaseType, Keys> &
37
- Readonly<HomomorphicPick<BaseType, Keys>>
39
+ Except<BaseType, Keys> &
40
+ Readonly<HomomorphicPick<BaseType, Keys>>
38
41
  >
39
42
  : never;
@@ -1,11 +1,11 @@
1
- import type {IsAny} from './is-any';
2
- import type {NonRecursiveType, StringToNumber} from './internal';
3
- import type {Paths} from './paths';
4
- import type {SetRequired} from './set-required';
5
- import type {SimplifyDeep} from './simplify-deep';
6
- import type {UnionToTuple} from './union-to-tuple';
7
- import type {RequiredDeep} from './required-deep';
8
- import type {UnknownArray} from './unknown-array';
1
+ import type {IsAny} from './is-any.d.ts';
2
+ import type {NonRecursiveType, StringToNumber} from './internal/index.d.ts';
3
+ import type {Paths} from './paths.d.ts';
4
+ import type {SetRequired} from './set-required.d.ts';
5
+ import type {SimplifyDeep} from './simplify-deep.d.ts';
6
+ import type {UnionToTuple} from './union-to-tuple.d.ts';
7
+ import type {RequiredDeep} from './required-deep.d.ts';
8
+ import type {UnknownArray} from './unknown-array.d.ts';
9
9
 
10
10
  /**
11
11
  Create a type that makes the given keys required. You can specify deeply nested key paths. The remaining keys are kept as is.
@@ -25,12 +25,12 @@ type Foo = {
25
25
  }
26
26
 
27
27
  type SomeRequiredDeep = SetRequiredDeep<Foo, 'a' | `c.${number}.d`>;
28
- // type SomeRequiredDeep = {
28
+ //=> {
29
29
  // a: number; // Is now required
30
30
  // b?: string;
31
- // c: {
32
- // d: number // Is now required
33
- // }[]
31
+ // c?: {
32
+ // d: number; // Is now required
33
+ // }[];
34
34
  // }
35
35
 
36
36
  // Set specific indices in an array to be required.
@@ -1,8 +1,9 @@
1
- import type {Except} from './except';
2
- import type {HomomorphicPick, IfArrayReadonly} from './internal';
3
- import type {OptionalKeysOf} from './optional-keys-of';
4
- import type {Simplify} from './simplify';
5
- import type {UnknownArray} from './unknown-array';
1
+ import type {Except} from './except.d.ts';
2
+ import type {If} from './if.d.ts';
3
+ import type {HomomorphicPick, IsArrayReadonly} from './internal/index.d.ts';
4
+ import type {OptionalKeysOf} from './optional-keys-of.d.ts';
5
+ import type {Simplify} from './simplify.d.ts';
6
+ import type {UnknownArray} from './unknown-array.d.ts';
6
7
 
7
8
  /**
8
9
  Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the `SetOptional` type.
@@ -34,15 +35,21 @@ type ArrayExample = SetRequired<[number?, number?, number?], 0 | 1>;
34
35
  @category Object
35
36
  */
36
37
  export type SetRequired<BaseType, Keys extends keyof BaseType> =
38
+ (BaseType extends (...arguments_: never) => any
39
+ ? (...arguments_: Parameters<BaseType>) => ReturnType<BaseType>
40
+ : unknown)
41
+ & _SetRequired<BaseType, Keys>;
42
+
43
+ type _SetRequired<BaseType, Keys extends keyof BaseType> =
37
44
  BaseType extends UnknownArray
38
45
  ? SetArrayRequired<BaseType, Keys> extends infer ResultantArray
39
- ? IfArrayReadonly<BaseType, Readonly<ResultantArray>, ResultantArray>
46
+ ? If<IsArrayReadonly<BaseType>, Readonly<ResultantArray>, ResultantArray>
40
47
  : never
41
48
  : Simplify<
42
49
  // Pick just the keys that are optional from the base type.
43
- Except<BaseType, Keys> &
50
+ Except<BaseType, Keys> &
44
51
  // Pick the keys that should be required from the base type and make them required.
45
- Required<HomomorphicPick<BaseType, Keys>>
52
+ Required<HomomorphicPick<BaseType, Keys>>
46
53
  >;
47
54
 
48
55
  /**
@@ -1,4 +1,4 @@
1
- import type {IsUnknown} from './is-unknown';
1
+ import type {IsUnknown} from './is-unknown.d.ts';
2
2
 
3
3
  /**
4
4
  Create a function type with a return type of your choice and the same parameters as the given function type.
@@ -1,6 +1,6 @@
1
- import type {NonRecursiveType, UnionMin, UnionMax, TupleLength, StaticPartOfArray, VariablePartOfArray, IsArrayReadonly, SetArrayAccess, ApplyDefaultOptions} from './internal';
2
- import type {IsNever} from './is-never';
3
- import type {UnknownArray} from './unknown-array';
1
+ import type {NonRecursiveType, UnionMin, UnionMax, TupleLength, StaticPartOfArray, VariablePartOfArray, IsArrayReadonly, SetArrayAccess, ApplyDefaultOptions} from './internal/index.d.ts';
2
+ import type {IsNever} from './is-never.d.ts';
3
+ import type {UnknownArray} from './unknown-array.d.ts';
4
4
 
5
5
  /**
6
6
  SharedUnionFieldsDeep options.
@@ -128,8 +128,8 @@ Same as `SharedUnionFieldsDeep`, but accepts only `UnknownArray`s and as inputs.
128
128
  type SharedArrayUnionFieldsDeep<Union extends UnknownArray, Options extends Required<SharedUnionFieldsDeepOptions>> =
129
129
  // Restore the readonly modifier of the array.
130
130
  SetArrayAccess<
131
- InternalSharedArrayUnionFieldsDeep<Union, Options>,
132
- IsArrayReadonly<Union>
131
+ InternalSharedArrayUnionFieldsDeep<Union, Options>,
132
+ IsArrayReadonly<Union>
133
133
  >;
134
134
 
135
135
  /**
@@ -155,13 +155,13 @@ type InternalSharedArrayUnionFieldsDeep<
155
155
  // Due to `ResultTuple` is the maximum possible fixed-length part of the tuple,
156
156
  // so we can use `StaticPartOfArray` to get the rest of the union.
157
157
  ...Array<
158
- SharedUnionFieldsDeep<VariablePartOfArray<Union>[number], Options>
158
+ SharedUnionFieldsDeep<VariablePartOfArray<Union>[number], Options>
159
159
  >,
160
160
  ]
161
161
  // Build the fixed-length tuple recursively.
162
162
  : InternalSharedArrayUnionFieldsDeep<
163
- Union, Options,
164
- [...ResultTuple, SharedUnionFieldsDeep<Union[ResultTuple['length']], Options>]
163
+ Union, Options,
164
+ [...ResultTuple, SharedUnionFieldsDeep<Union[ResultTuple['length']], Options>]
165
165
  >
166
166
  // Rule 2: If at least one of the arrays in the union have fixed lengths,
167
167
  // like `Array<string> | [number, string]`,
@@ -173,6 +173,6 @@ type InternalSharedArrayUnionFieldsDeep<
173
173
  ? ResultTuple
174
174
  // As above, build tuple recursively.
175
175
  : InternalSharedArrayUnionFieldsDeep<
176
- Union, Options,
177
- [...ResultTuple, SharedUnionFieldsDeep<Union[ResultTuple['length']], Options>]
176
+ Union, Options,
177
+ [...ResultTuple, SharedUnionFieldsDeep<Union[ResultTuple['length']], Options>]
178
178
  >;
@@ -1,7 +1,8 @@
1
- import type {NonRecursiveType, IsUnion} from './internal';
2
- import type {IsNever} from './is-never';
3
- import type {Simplify} from './simplify';
4
- import type {UnknownArray} from './unknown-array';
1
+ import type {NonRecursiveType} from './internal/index.d.ts';
2
+ import type {IsNever} from './is-never.d.ts';
3
+ import type {IsUnion} from './is-union.d.ts';
4
+ import type {Simplify} from './simplify.d.ts';
5
+ import type {UnknownArray} from './unknown-array.d.ts';
5
6
 
6
7
  /**
7
8
  Create a type with shared fields from a union of object types.
@@ -1,5 +1,5 @@
1
- import type {ConditionalSimplifyDeep} from './conditional-simplify';
2
- import type {NonRecursiveType} from './internal';
1
+ import type {ConditionalSimplifyDeep} from './conditional-simplify-deep.d.ts';
2
+ import type {NonRecursiveType} from './internal/index.d.ts';
3
3
 
4
4
  /**
5
5
  Deeply simplifies an object type.
@@ -109,7 +109,7 @@ type SimplifyDeepProperties = SimplifyDeep<Properties1 & Properties2, ComplexTyp
109
109
  */
110
110
  export type SimplifyDeep<Type, ExcludeType = never> =
111
111
  ConditionalSimplifyDeep<
112
- Type,
112
+ Type,
113
113
  ExcludeType | NonRecursiveType | Set<unknown> | Map<unknown, unknown>,
114
114
  object
115
115
  >;
@@ -1,5 +1,6 @@
1
- import type {IfEmptyObject} from './if-empty-object';
2
- import type {IsUnion} from './internal';
1
+ import type {IsEmptyObject} from './empty-object.d.ts';
2
+ import type {If} from './if.d.ts';
3
+ import type {IsUnion} from './is-union.d.ts';
3
4
 
4
5
  /**
5
6
  Create a type that only accepts an object with a single key.
@@ -26,4 +27,4 @@ someFunction({
26
27
  export type SingleKeyObject<ObjectType> =
27
28
  IsUnion<keyof ObjectType> extends true
28
29
  ? never
29
- : IfEmptyObject<ObjectType, never, ObjectType>;
30
+ : If<IsEmptyObject<ObjectType>, never, ObjectType>;
@@ -1,6 +1,6 @@
1
- import type {DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case';
2
- import type {ApplyDefaultOptions} from './internal';
3
- import type {WordsOptions} from './words';
1
+ import type {DefaultDelimiterCaseOptions, DelimiterCase} from './delimiter-case.d.ts';
2
+ import type {ApplyDefaultOptions} from './internal/index.d.ts';
3
+ import type {WordsOptions} from './words.d.ts';
4
4
 
5
5
  /**
6
6
  Convert a string literal to snake-case.
@@ -1,7 +1,7 @@
1
- import type {DefaultDelimiterCaseOptions} from './delimiter-case';
2
- import type {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
3
- import type {ApplyDefaultOptions} from './internal';
4
- import type {WordsOptions} from './words';
1
+ import type {DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
2
+ import type {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep.d.ts';
3
+ import type {ApplyDefaultOptions} from './internal/index.d.ts';
4
+ import type {WordsOptions} from './words.d.ts';
5
5
 
6
6
  /**
7
7
  Convert object properties to snake case recursively.
@@ -1,7 +1,7 @@
1
- import type {DefaultDelimiterCaseOptions} from './delimiter-case';
2
- import type {DelimiterCasedProperties} from './delimiter-cased-properties';
3
- import type {ApplyDefaultOptions} from './internal';
4
- import type {WordsOptions} from './words';
1
+ import type {DefaultDelimiterCaseOptions} from './delimiter-case.d.ts';
2
+ import type {DelimiterCasedProperties} from './delimiter-cased-properties.d.ts';
3
+ import type {ApplyDefaultOptions} from './internal/index.d.ts';
4
+ import type {WordsOptions} from './words.d.ts';
5
5
 
6
6
  /**
7
7
  Convert object properties to snake case but not recursively.
package/source/split.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type {And} from './and';
2
- import type {ApplyDefaultOptions, Not} from './internal';
3
- import type {IsStringLiteral} from './is-literal';
4
- import type {Or} from './or';
1
+ import type {And} from './and.d.ts';
2
+ import type {ApplyDefaultOptions, Not} from './internal/index.d.ts';
3
+ import type {IsStringLiteral} from './is-literal.d.ts';
4
+ import type {Or} from './or.d.ts';
5
5
 
6
6
  /**
7
7
  Split options.
@@ -12,9 +12,7 @@ type SplitOptions = {
12
12
  /**
13
13
  When enabled, instantiations with non-literal string types (e.g., `string`, `Uppercase<string>`, `on${string}`) simply return back `string[]` without performing any splitting, as the exact structure cannot be statically determined.
14
14
 
15
- Note: In the future, this option might be enabled by default, so if you currently rely on this being disabled, you should consider explicitly enabling it.
16
-
17
- @default false
15
+ @default true
18
16
 
19
17
  @example
20
18
  ```ts
@@ -35,7 +33,7 @@ type SplitOptions = {
35
33
  };
36
34
 
37
35
  type DefaultSplitOptions = {
38
- strictLiteralChecks: false;
36
+ strictLiteralChecks: true;
39
37
  };
40
38
 
41
39
  /**
@@ -80,7 +78,9 @@ type SplitHelper<
80
78
  ? S extends `${infer Head}${Delimiter}${infer Tail}`
81
79
  ? SplitHelper<Tail, Delimiter, Options, [...Accumulator, Head]>
82
80
  : Delimiter extends ''
83
- ? Accumulator
81
+ ? S extends ''
82
+ ? Accumulator
83
+ : [...Accumulator, S]
84
84
  : [...Accumulator, S]
85
85
  // Otherwise, return `string[]`
86
86
  : string[]
@@ -1,12 +1,12 @@
1
- import type {RequiredKeysOf} from './required-keys-of';
2
- import type {Simplify} from './simplify';
1
+ import type {RequiredKeysOf} from './required-keys-of.d.ts';
2
+ import type {Simplify} from './simplify.d.ts';
3
3
 
4
4
  type SpreadObject<FirstType extends object, SecondType extends object> = {
5
5
  [Key in keyof FirstType]: Key extends keyof SecondType
6
6
  ? FirstType[Key] | Required<SecondType>[Key]
7
7
  : FirstType[Key];
8
8
  } & Pick<
9
- SecondType,
9
+ SecondType,
10
10
  RequiredKeysOf<SecondType> | Exclude<keyof SecondType, keyof FirstType>
11
11
  >;
12
12
 
@@ -1,5 +1,5 @@
1
- import type {IsNumericLiteral} from './is-literal';
2
- import type {IsNegative} from './numeric';
1
+ import type {IsNumericLiteral} from './is-literal.d.ts';
2
+ import type {IsNegative} from './numeric.d.ts';
3
3
 
4
4
  /**
5
5
  Returns a new string which contains the specified number of copies of a given string, just like `String#repeat()`.
@@ -1,6 +1,6 @@
1
- import type {Join} from './join';
2
- import type {ArraySlice} from './array-slice';
3
- import type {StringToArray} from './internal';
1
+ import type {Join} from './join.d.ts';
2
+ import type {ArraySlice} from './array-slice.d.ts';
3
+ import type {StringToArray} from './internal/index.d.ts';
4
4
 
5
5
  /**
6
6
  Returns a string slice of a given range, just like `String#slice()`.