type-fest 5.2.0 → 5.3.0

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 (141) hide show
  1. package/package.json +5 -2
  2. package/source/all-union-fields.d.ts +8 -7
  3. package/source/array-slice.d.ts +29 -8
  4. package/source/array-splice.d.ts +8 -6
  5. package/source/arrayable.d.ts +1 -1
  6. package/source/async-return-type.d.ts +6 -3
  7. package/source/asyncify.d.ts +7 -16
  8. package/source/camel-case.d.ts +3 -3
  9. package/source/camel-cased-properties-deep.d.ts +4 -4
  10. package/source/camel-cased-properties.d.ts +2 -2
  11. package/source/characters.d.ts +8 -3
  12. package/source/conditional-except.d.ts +6 -6
  13. package/source/conditional-pick-deep.d.ts +2 -2
  14. package/source/conditional-pick.d.ts +6 -6
  15. package/source/delimiter-case.d.ts +3 -3
  16. package/source/delimiter-cased-properties-deep.d.ts +6 -6
  17. package/source/delimiter-cased-properties.d.ts +2 -2
  18. package/source/distributed-omit.d.ts +15 -10
  19. package/source/distributed-pick.d.ts +12 -7
  20. package/source/empty-object.d.ts +7 -4
  21. package/source/entries.d.ts +3 -3
  22. package/source/entry.d.ts +3 -3
  23. package/source/exact.d.ts +5 -3
  24. package/source/except.d.ts +5 -3
  25. package/source/exclude-rest-element.d.ts +1 -1
  26. package/source/exclude-strict.d.ts +4 -0
  27. package/source/extract-rest-element.d.ts +1 -1
  28. package/source/extract-strict.d.ts +4 -0
  29. package/source/find-global-type.d.ts +7 -5
  30. package/source/fixed-length-array.d.ts +8 -0
  31. package/source/get.d.ts +27 -28
  32. package/source/global-this.d.ts +2 -1
  33. package/source/greater-than-or-equal.d.ts +3 -3
  34. package/source/greater-than.d.ts +3 -3
  35. package/source/has-optional-keys.d.ts +2 -2
  36. package/source/has-readonly-keys.d.ts +2 -2
  37. package/source/has-required-keys.d.ts +10 -10
  38. package/source/has-writable-keys.d.ts +2 -2
  39. package/source/if.d.ts +3 -3
  40. package/source/int-closed-range.d.ts +17 -7
  41. package/source/int-range.d.ts +17 -7
  42. package/source/internal/array.d.ts +4 -4
  43. package/source/internal/numeric.d.ts +7 -7
  44. package/source/internal/object.d.ts +13 -12
  45. package/source/internal/string.d.ts +15 -15
  46. package/source/internal/tuple.d.ts +5 -5
  47. package/source/internal/type.d.ts +6 -6
  48. package/source/invariant-of.d.ts +26 -19
  49. package/source/is-any.d.ts +2 -2
  50. package/source/is-equal.d.ts +4 -8
  51. package/source/is-integer.d.ts +1 -1
  52. package/source/is-literal.d.ts +13 -13
  53. package/source/is-lowercase.d.ts +3 -3
  54. package/source/is-never.d.ts +35 -23
  55. package/source/is-null.d.ts +1 -1
  56. package/source/is-optional-key-of.d.ts +4 -4
  57. package/source/is-readonly-key-of.d.ts +4 -4
  58. package/source/is-required-key-of.d.ts +4 -4
  59. package/source/is-unknown.d.ts +12 -23
  60. package/source/is-uppercase.d.ts +3 -3
  61. package/source/is-writable-key-of.d.ts +4 -4
  62. package/source/iterable-element.d.ts +3 -3
  63. package/source/join.d.ts +27 -18
  64. package/source/jsonifiable.d.ts +5 -5
  65. package/source/jsonify.d.ts +7 -8
  66. package/source/kebab-case.d.ts +3 -3
  67. package/source/kebab-cased-properties-deep.d.ts +6 -6
  68. package/source/kebab-cased-properties.d.ts +2 -2
  69. package/source/last-array-element.d.ts +5 -9
  70. package/source/less-than-or-equal.d.ts +3 -3
  71. package/source/less-than.d.ts +3 -3
  72. package/source/literal-to-primitive-deep.d.ts +40 -7
  73. package/source/literal-union.d.ts +2 -2
  74. package/source/merge-deep.d.ts +6 -8
  75. package/source/merge-exclusive.d.ts +7 -4
  76. package/source/merge.d.ts +2 -2
  77. package/source/multidimensional-array.d.ts +7 -15
  78. package/source/multidimensional-readonly-array.d.ts +7 -19
  79. package/source/non-empty-object.d.ts +1 -0
  80. package/source/non-empty-string.d.ts +3 -1
  81. package/source/non-empty-tuple.d.ts +1 -0
  82. package/source/numeric.d.ts +6 -4
  83. package/source/omit-deep.d.ts +13 -12
  84. package/source/omit-index-signature.d.ts +17 -20
  85. package/source/optional-keys-of.d.ts +4 -4
  86. package/source/override-properties.d.ts +11 -6
  87. package/source/package-json.d.ts +12 -0
  88. package/source/partial-on-undefined-deep.d.ts +2 -2
  89. package/source/pascal-case.d.ts +1 -1
  90. package/source/pascal-cased-properties-deep.d.ts +4 -4
  91. package/source/pascal-cased-properties.d.ts +2 -2
  92. package/source/paths.d.ts +12 -0
  93. package/source/pick-deep.d.ts +2 -2
  94. package/source/promisable.d.ts +2 -2
  95. package/source/readonly-deep.d.ts +45 -12
  96. package/source/readonly-keys-of.d.ts +3 -3
  97. package/source/readonly-tuple.d.ts +5 -3
  98. package/source/remove-prefix.d.ts +2 -0
  99. package/source/replace.d.ts +3 -3
  100. package/source/require-all-or-none.d.ts +2 -2
  101. package/source/require-at-least-one.d.ts +1 -1
  102. package/source/require-exactly-one.d.ts +1 -1
  103. package/source/require-one-or-none.d.ts +3 -3
  104. package/source/required-keys-of.d.ts +10 -4
  105. package/source/set-field-type.d.ts +2 -2
  106. package/source/set-non-nullable.d.ts +1 -1
  107. package/source/set-optional.d.ts +1 -1
  108. package/source/set-parameter-type.d.ts +12 -6
  109. package/source/set-readonly.d.ts +1 -1
  110. package/source/set-required-deep.d.ts +4 -4
  111. package/source/set-required.d.ts +1 -1
  112. package/source/set-return-type.d.ts +3 -3
  113. package/source/shared-union-fields-deep.d.ts +5 -5
  114. package/source/shared-union-fields.d.ts +5 -5
  115. package/source/simplify-deep.d.ts +2 -3
  116. package/source/simplify.d.ts +2 -1
  117. package/source/single-key-object.d.ts +4 -8
  118. package/source/snake-case.d.ts +3 -3
  119. package/source/snake-cased-properties-deep.d.ts +5 -5
  120. package/source/snake-cased-properties.d.ts +2 -2
  121. package/source/split.d.ts +4 -4
  122. package/source/spread.d.ts +2 -6
  123. package/source/string-repeat.d.ts +2 -2
  124. package/source/string-slice.d.ts +6 -6
  125. package/source/stringified.d.ts +2 -2
  126. package/source/structured-cloneable.d.ts +11 -16
  127. package/source/subtract.d.ts +7 -7
  128. package/source/sum.d.ts +6 -6
  129. package/source/tagged-union.d.ts +2 -2
  130. package/source/tagged.d.ts +15 -13
  131. package/source/trim.d.ts +1 -1
  132. package/source/tuple-of.d.ts +2 -0
  133. package/source/tuple-to-object.d.ts +2 -0
  134. package/source/tuple-to-union.d.ts +3 -2
  135. package/source/undefined-on-partial-deep.d.ts +5 -4
  136. package/source/union-to-intersection.d.ts +0 -28
  137. package/source/union-to-tuple.d.ts +3 -3
  138. package/source/value-of.d.ts +6 -26
  139. package/source/words.d.ts +2 -0
  140. package/source/writable-keys-of.d.ts +2 -2
  141. package/source/writable.d.ts +2 -0
package/source/exact.d.ts CHANGED
@@ -24,9 +24,10 @@ This is useful for function type-guarding to reject arguments with excess proper
24
24
  ```
25
25
  type OnlyAcceptName = {name: string};
26
26
 
27
- function onlyAcceptName(arguments_: OnlyAcceptName) {}
27
+ declare function onlyAcceptName(arguments_: OnlyAcceptName): void;
28
28
 
29
29
  // TypeScript complains about excess properties when an object literal is provided.
30
+ // @ts-expect-error
30
31
  onlyAcceptName({name: 'name', id: 1});
31
32
  //=> `id` is excess
32
33
 
@@ -39,13 +40,14 @@ Having `Exact` allows TypeScript to reject excess properties.
39
40
 
40
41
  @example
41
42
  ```
42
- import {Exact} from 'type-fest';
43
+ import type {Exact} from 'type-fest';
43
44
 
44
45
  type OnlyAcceptName = {name: string};
45
46
 
46
- function onlyAcceptNameImproved<T extends Exact<OnlyAcceptName, T>>(arguments_: T) {}
47
+ declare function onlyAcceptNameImproved<T extends Exact<OnlyAcceptName, T>>(arguments_: T): void;
47
48
 
48
49
  const invalidInput = {name: 'name', id: 1};
50
+ // @ts-expect-error
49
51
  onlyAcceptNameImproved(invalidInput); // Compilation error
50
52
  ```
51
53
 
@@ -66,12 +66,14 @@ type Foo = {
66
66
  type FooWithoutA = Except<Foo, 'a'>;
67
67
  //=> {b: string}
68
68
 
69
+ // @ts-expect-error
69
70
  const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
70
71
  //=> errors: 'a' does not exist in type '{ b: string; }'
71
72
 
72
73
  type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
73
74
  //=> {a: number} & Partial<Record<"b", never>>
74
75
 
76
+ // @ts-expect-error
75
77
  const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
76
78
  //=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
77
79
 
@@ -88,12 +90,12 @@ type UserData = {
88
90
 
89
91
  // `Omit` clearly doesn't behave as expected in this case:
90
92
  type PostPayload = Omit<UserData, 'email'>;
91
- //=> type PostPayload = { [x: string]: string; [x: number]: string; }
93
+ //=> { [x: string]: string; [x: number]: string; }
92
94
 
93
95
  // In situations like this, `Except` works better.
94
96
  // It simply removes the `email` key while preserving all the other keys.
95
- type PostPayload = Except<UserData, 'email'>;
96
- //=> type PostPayload = { [x: string]: string; name: string; role: 'admin' | 'user'; }
97
+ type PostPayloadFixed = Except<UserData, 'email'>;
98
+ //=> { [x: string]: string; name: string; role: 'admin' | 'user'; }
97
99
  ```
98
100
 
99
101
  @category Object
@@ -16,7 +16,7 @@ type T1 = ExcludeRestElement<[number, ...string[], string, 'foo']>;
16
16
  type T2 = ExcludeRestElement<[...boolean[], string]>;
17
17
  //=> [string]
18
18
 
19
- type T3 = ExcludeRestElement<[...'foo'[], true]>;
19
+ type T3 = ExcludeRestElement<[...Array<'foo'>, true]>;
20
20
  //=> [true]
21
21
 
22
22
  type T4 = ExcludeRestElement<[number, string]>;
@@ -6,6 +6,7 @@ For example, `ExcludeStrict<string | number | boolean, number | bigint>` will er
6
6
  @example
7
7
  ```
8
8
  // Valid Examples
9
+ import type {ExcludeStrict} from 'type-fest';
9
10
 
10
11
  type Example1 = ExcludeStrict<{status: 'success'; data: string[]} | {status: 'error'; error: string}, {status: 'success'}>;
11
12
  //=> {status: 'error'; error: string}
@@ -20,13 +21,16 @@ type Example3 = ExcludeStrict<{x: number; y: number} | [number, number], unknown
20
21
  @example
21
22
  ```
22
23
  // Invalid Examples
24
+ import type {ExcludeStrict} from 'type-fest';
23
25
 
24
26
  // `'xxl'` cannot exclude anything from `'xs' | 's' | 'm' | 'l' | 'xl'`
27
+ // @ts-expect-error
25
28
  type Example1 = ExcludeStrict<'xs' | 's' | 'm' | 'l' | 'xl', 'xl' | 'xxl'>;
26
29
  // ~~~~~~~~~~~~
27
30
  // Error: Type "'xl' | 'xxl'" does not satisfy the constraint 'never'.
28
31
 
29
32
  // `unknown[]` cannot exclude anything from `{x: number; y: number} | {x: string; y: string}`
33
+ // @ts-expect-error
30
34
  type Example2 = ExcludeStrict<{x: number; y: number} | {x: string; y: string}, unknown[]>;
31
35
  // ~~~~~~~~~
32
36
  // Error: Type 'unknown[]' does not satisfy the constraint 'never'.
@@ -14,7 +14,7 @@ type T1 = ExtractRestElement<[number, ...string[], string, 'foo']>;
14
14
  type T2 = ExtractRestElement<[...boolean[], string]>;
15
15
  //=> boolean
16
16
 
17
- type T3 = ExtractRestElement<[...'foo'[], true]>;
17
+ type T3 = ExtractRestElement<[...Array<'foo'>, true]>;
18
18
  //=> 'foo'
19
19
 
20
20
  type T4 = ExtractRestElement<[number, string]>;
@@ -6,6 +6,7 @@ For example, `ExtractStrict<string | number | boolean, number | bigint>` will er
6
6
  @example
7
7
  ```
8
8
  // Valid Examples
9
+ import type {ExtractStrict} from 'type-fest';
9
10
 
10
11
  type Example1 = ExtractStrict<{status: 'success'; data: string[]} | {status: 'error'; error: string}, {status: 'success'}>;
11
12
  //=> {status: 'success'; data: string[]}
@@ -20,13 +21,16 @@ type Example3 = ExtractStrict<{x: number; y: number} | [number, number], unknown
20
21
  @example
21
22
  ```
22
23
  // Invalid Examples
24
+ import type {ExtractStrict} from 'type-fest';
23
25
 
24
26
  // `'xxl'` cannot extract anything from `'xs' | 's' | 'm' | 'l' | 'xl'`
27
+ // @ts-expect-error
25
28
  type Example1 = ExtractStrict<'xs' | 's' | 'm' | 'l' | 'xl', 'xl' | 'xxl'>;
26
29
  // ~~~~~~~~~~~~
27
30
  // Error: Type "'xl' | 'xxl'" does not satisfy the constraint 'never'.
28
31
 
29
32
  // `unknown[]` cannot extract anything from `{x: number; y: number} | {x: string; y: string}`
33
+ // @ts-expect-error
30
34
  type Example2 = ExtractStrict<{x: number; y: number} | {x: string; y: string}, unknown[]>;
31
35
  // ~~~~~~~~~
32
36
  // Error: Type 'unknown[]' does not satisfy the constraint 'never'.
@@ -9,12 +9,12 @@ import type {FindGlobalType} from 'type-fest';
9
9
 
10
10
  declare global {
11
11
  const foo: number; // let and const don't work
12
- var bar: string; // var works
12
+ var bar: string; // var works
13
13
  }
14
14
 
15
- type FooType = FindGlobalType<'foo'> //=> never (let/const don't work)
16
- type BarType = FindGlobalType<'bar'> //=> string
17
- type OtherType = FindGlobalType<'other'> //=> never (no global named 'other')
15
+ type FooType = FindGlobalType<'foo'>; //=> never (let/const don't work)
16
+ type BarType = FindGlobalType<'bar'>; //=> string
17
+ type OtherType = FindGlobalType<'other'>; //=> never (no global named 'other')
18
18
  ```
19
19
 
20
20
  @category Utilities
@@ -48,7 +48,9 @@ declare global {
48
48
  class Foo {}
49
49
 
50
50
  // interface + constructor style works
51
- interface Bar {}
51
+ interface Bar {
52
+ bar: string;
53
+ }
52
54
  var Bar: new () => Bar; // Not let or const
53
55
  }
54
56
 
@@ -32,6 +32,7 @@ import type {FixedLengthArray} from 'type-fest';
32
32
 
33
33
  const color: FixedLengthArray<number, 3> = [255, 128, 64];
34
34
 
35
+ // @ts-expect-error
35
36
  color.pop();
36
37
  //=> Error: Property 'pop' does not exist on type 'FixedLengthArray<number, 3>'.
37
38
  ```
@@ -42,6 +43,8 @@ Use-cases:
42
43
 
43
44
  @example
44
45
  ```
46
+ import type {FixedLengthArray} from 'type-fest';
47
+
45
48
  let color: FixedLengthArray<number, 3> = [255, 128, 64];
46
49
 
47
50
  const red = color[0];
@@ -51,6 +54,7 @@ const green = color[1];
51
54
  const blue = color[2];
52
55
  //=> number
53
56
 
57
+ // @ts-expect-error
54
58
  const alpha = color[3];
55
59
  //=> Error: Property '3' does not exist on type 'FixedLengthArray<number, 3>'.
56
60
 
@@ -60,15 +64,19 @@ color[1] = 64;
60
64
  color[2] = 32;
61
65
 
62
66
  // But you cannot write to out-of-bounds indices.
67
+ // @ts-expect-error
63
68
  color[3] = 0.5;
64
69
  //=> Error: Property '3' does not exist on type 'FixedLengthArray<number, 3>'.
65
70
 
71
+ // @ts-expect-error
66
72
  color.push(0.5);
67
73
  //=> Error: Property 'push' does not exist on type 'FixedLengthArray<number, 3>'.
68
74
 
75
+ // @ts-expect-error
69
76
  color = [0, 128, 255, 0.5];
70
77
  //=> Error: Type '[number, number, number, number]' is not assignable to type 'FixedLengthArray<number, 3>'. Types of property 'length' are incompatible.
71
78
 
79
+ // @ts-expect-error
72
80
  color.length = 4;
73
81
  //=> Error: Cannot assign to 'length' because it is a read-only property.
74
82
 
package/source/get.d.ts CHANGED
@@ -58,10 +58,10 @@ Splits a dot-prop style path into a tuple comprised of the properties in the pat
58
58
 
59
59
  @example
60
60
  ```
61
- ToPath<'foo.bar.baz'>
61
+ type A = ToPath<'foo.bar.baz'>;
62
62
  //=> ['foo', 'bar', 'baz']
63
63
 
64
- ToPath<'foo[0].bar.baz'>
64
+ type B = ToPath<'foo[0].bar.baz'>;
65
65
  //=> ['foo', '0', 'bar', 'baz']
66
66
  ```
67
67
  */
@@ -84,10 +84,10 @@ Returns true if `LongString` is made up out of `Substring` repeated 0 or more ti
84
84
 
85
85
  @example
86
86
  ```
87
- ConsistsOnlyOf<'aaa', 'a'> //=> true
88
- ConsistsOnlyOf<'ababab', 'ab'> //=> true
89
- ConsistsOnlyOf<'aBa', 'a'> //=> false
90
- ConsistsOnlyOf<'', 'a'> //=> true
87
+ type A = ConsistsOnlyOf<'aaa', 'a'>; //=> true
88
+ type B = ConsistsOnlyOf<'ababab', 'ab'>; //=> true
89
+ type C = ConsistsOnlyOf<'aBa', 'a'>; //=> false
90
+ type D = ConsistsOnlyOf<'', 'a'>; //=> true
91
91
  ```
92
92
  */
93
93
  type ConsistsOnlyOf<LongString extends string, Substring extends string> =
@@ -168,38 +168,37 @@ Use-case: Retrieve a property from deep inside an API response or some other com
168
168
  @example
169
169
  ```
170
170
  import type {Get} from 'type-fest';
171
- import * as lodash from 'lodash';
172
171
 
173
- const get = <BaseType, Path extends string | readonly string[]>(object: BaseType, path: Path): Get<BaseType, Path> =>
174
- lodash.get(object, path);
172
+ declare function get<BaseType, const Path extends string | readonly string[]>(object: BaseType, path: Path): Get<BaseType, Path>;
175
173
 
176
- interface ApiResponse {
174
+ type ApiResponse = {
177
175
  hits: {
178
176
  hits: Array<{
179
- _id: string
177
+ _id: string;
180
178
  _source: {
181
179
  name: Array<{
182
- given: string[]
183
- family: string
184
- }>
185
- birthDate: string
186
- }
187
- }>
188
- }
189
- }
190
-
191
- const getName = (apiResponse: ApiResponse) =>
192
- get(apiResponse, 'hits.hits[0]._source.name');
193
- //=> Array<{given: string[]; family: string}> | undefined
180
+ given: string[];
181
+ family: string;
182
+ }>;
183
+ birthDate: string;
184
+ };
185
+ }>;
186
+ };
187
+ };
188
+
189
+ const getName = (apiResponse: ApiResponse) => get(apiResponse, 'hits.hits[0]._source.name');
190
+ //=> (apiResponse: ApiResponse) => {given: string[]; family: string}[] | undefined
194
191
 
195
192
  // Path also supports a readonly array of strings
196
- const getNameWithPathArray = (apiResponse: ApiResponse) =>
197
- get(apiResponse, ['hits','hits', '0', '_source', 'name'] as const);
198
- //=> Array<{given: string[]; family: string}> | undefined
193
+ const getNameWithPathArray = (apiResponse: ApiResponse) => get(apiResponse, ['hits', 'hits', '0', '_source', 'name']);
194
+ //=> (apiResponse: ApiResponse) => {given: string[]; family: string}[] | undefined
199
195
 
200
196
  // Non-strict mode:
201
- Get<string[], '3', {strict: false}> //=> string
202
- Get<Record<string, string>, 'foo', {strict: true}> // => string
197
+ type A = Get<string[], '3', {strict: false}>;
198
+ //=> string
199
+
200
+ type B = Get<Record<string, string>, 'foo', {strict: true}>;
201
+ // => string | undefined
203
202
  ```
204
203
 
205
204
  @category Object
@@ -13,7 +13,8 @@ type ExtraGlobals = GlobalThis & {
13
13
  readonly GLOBAL_TOKEN: string;
14
14
  };
15
15
 
16
- (globalThis as ExtraGlobals).GLOBAL_TOKEN;
16
+ const globalToken = (globalThis as ExtraGlobals).GLOBAL_TOKEN;
17
+ //=> string
17
18
  ```
18
19
 
19
20
  @category Type
@@ -7,13 +7,13 @@ Returns a boolean for whether a given number is greater than or equal to another
7
7
  ```
8
8
  import type {GreaterThanOrEqual} from 'type-fest';
9
9
 
10
- GreaterThanOrEqual<1, -5>;
10
+ type A = GreaterThanOrEqual<1, -5>;
11
11
  //=> true
12
12
 
13
- GreaterThanOrEqual<1, 1>;
13
+ type B = GreaterThanOrEqual<1, 1>;
14
14
  //=> true
15
15
 
16
- GreaterThanOrEqual<1, 5>;
16
+ type C = GreaterThanOrEqual<1, 5>;
17
17
  //=> false
18
18
  ```
19
19
  */
@@ -11,13 +11,13 @@ Returns a boolean for whether a given number is greater than another number.
11
11
  ```
12
12
  import type {GreaterThan} from 'type-fest';
13
13
 
14
- GreaterThan<1, -5>;
14
+ type A = GreaterThan<1, -5>;
15
15
  //=> true
16
16
 
17
- GreaterThan<1, 1>;
17
+ type B = GreaterThan<1, 1>;
18
18
  //=> false
19
19
 
20
- GreaterThan<1, 5>;
20
+ type C = GreaterThan<1, 5>;
21
21
  //=> false
22
22
  ```
23
23
  */
@@ -12,8 +12,8 @@ import type {HasOptionalKeys, OptionalKeysOf} from 'type-fest';
12
12
  type UpdateService<Entity extends object> = {
13
13
  removeField: HasOptionalKeys<Entity> extends true
14
14
  ? (field: OptionalKeysOf<Entity>) => Promise<void>
15
- : never
16
- }
15
+ : never;
16
+ };
17
17
  ```
18
18
 
19
19
  @category Utilities
@@ -12,8 +12,8 @@ import type {HasReadonlyKeys, ReadonlyKeysOf} from 'type-fest';
12
12
  type UpdateService<Entity extends object> = {
13
13
  removeField: HasReadonlyKeys<Entity> extends true
14
14
  ? (field: ReadonlyKeysOf<Entity>) => Promise<void>
15
- : never
16
- }
15
+ : never;
16
+ };
17
17
  ```
18
18
 
19
19
  @category Utilities
@@ -16,40 +16,40 @@ type GeneratorOptions<Template extends object> = {
16
16
  ? {template: Template}
17
17
  : {template?: Template});
18
18
 
19
- interface Template1 {
19
+ type Template1 = {
20
20
  optionalSubParam?: string;
21
- }
21
+ };
22
22
 
23
- interface Template2 {
23
+ type Template2 = {
24
24
  requiredSubParam: string;
25
- }
25
+ };
26
26
 
27
27
  type Options1 = GeneratorOptions<Template1>;
28
28
  type Options2 = GeneratorOptions<Template2>;
29
29
 
30
30
  const optA: Options1 = {
31
31
  prop1: 0,
32
- prop2: 'hi'
32
+ prop2: 'hi',
33
33
  };
34
34
  const optB: Options1 = {
35
35
  prop1: 0,
36
36
  prop2: 'hi',
37
- template: {}
37
+ template: {},
38
38
  };
39
39
  const optC: Options1 = {
40
40
  prop1: 0,
41
41
  prop2: 'hi',
42
42
  template: {
43
- optionalSubParam: 'optional value'
44
- }
43
+ optionalSubParam: 'optional value',
44
+ },
45
45
  };
46
46
 
47
47
  const optD: Options2 = {
48
48
  prop1: 0,
49
49
  prop2: 'hi',
50
50
  template: {
51
- requiredSubParam: 'required value'
52
- }
51
+ requiredSubParam: 'required value',
52
+ },
53
53
  };
54
54
 
55
55
  ```
@@ -12,8 +12,8 @@ import type {HasWritableKeys, WritableKeysOf} from 'type-fest';
12
12
  type UpdateService<Entity extends object> = {
13
13
  removeField: HasWritableKeys<Entity> extends true
14
14
  ? (field: WritableKeysOf<Entity>) => Promise<void>
15
- : never
16
- }
15
+ : never;
16
+ };
17
17
  ```
18
18
 
19
19
  @category Utilities
package/source/if.d.ts CHANGED
@@ -12,7 +12,7 @@ Note:
12
12
 
13
13
  @example
14
14
  ```
15
- import {If} from 'type-fest';
15
+ import type {If} from 'type-fest';
16
16
 
17
17
  type A = If<true, 'yes', 'no'>;
18
18
  //=> 'yes'
@@ -32,7 +32,7 @@ type E = If<never, 'yes', 'no'>;
32
32
 
33
33
  @example
34
34
  ```
35
- import {If, IsAny, IsNever} from 'type-fest';
35
+ import type {If, IsAny, IsNever} from 'type-fest';
36
36
 
37
37
  type A = If<IsAny<unknown>, 'is any', 'not any'>;
38
38
  //=> 'not any'
@@ -43,7 +43,7 @@ type B = If<IsNever<never>, 'is never', 'not never'>;
43
43
 
44
44
  @example
45
45
  ```
46
- import {If, IsEqual} from 'type-fest';
46
+ import type {If, IsEqual} from 'type-fest';
47
47
 
48
48
  type IfEqual<T, U, IfBranch, ElseBranch> = If<IsEqual<T, U>, IfBranch, ElseBranch>;
49
49
 
@@ -12,22 +12,32 @@ Note: `Start` or `End` must be non-negative and smaller than `999`.
12
12
 
13
13
  Use-cases:
14
14
  1. This can be used to define a set of valid input/output values. for example:
15
- ```
16
- type Age = IntClosedRange<0, 120>; //=> 0 | 1 | 2 | ... | 119 | 120
17
- type FontSize = IntClosedRange<10, 20>; //=> 10 | 11 | ... | 19 | 20
18
- type EvenNumber = IntClosedRange<0, 10, 2>; //=> 0 | 2 | 4 | 6 | 8 | 10
19
- ```
15
+
16
+ @example
17
+ ```
18
+ import type {IntClosedRange} from 'type-fest';
19
+
20
+ type Age = IntClosedRange<0, 120>;
21
+ //=> 0 | 1 | 2 | ... | 119 | 120
22
+
23
+ type FontSize = IntClosedRange<10, 20>;
24
+ //=> 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
25
+
26
+ type EvenNumber = IntClosedRange<0, 10, 2>;
27
+ //=> 0 | 2 | 4 | 6 | 8 | 10
28
+ ```
29
+
20
30
  2. This can be used to define random numbers in a range. For example, `type RandomNumber = IntClosedRange<0, 100>;`
21
31
 
22
32
  @example
23
33
  ```
24
34
  import type {IntClosedRange} from 'type-fest';
25
35
 
26
- // Create union type `0 | 1 | ... | 9`
27
36
  type ZeroToNine = IntClosedRange<0, 9>;
37
+ //=> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
28
38
 
29
- // Create union type `100 | 200 | 300 | ... | 900`
30
39
  type Hundreds = IntClosedRange<100, 900, 100>;
40
+ //=> 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
31
41
  ```
32
42
 
33
43
  @see {@link IntRange}
@@ -12,22 +12,32 @@ Note: `Start` or `End` must be non-negative and smaller than `1000`.
12
12
 
13
13
  Use-cases:
14
14
  1. This can be used to define a set of valid input/output values. for example:
15
- ```
16
- type Age = IntRange<0, 120>;
17
- type FontSize = IntRange<10, 20>;
18
- type EvenNumber = IntRange<0, 11, 2>; //=> 0 | 2 | 4 | 6 | 8 | 10
19
- ```
15
+
16
+ @example
17
+ ```
18
+ import type {IntRange} from 'type-fest';
19
+
20
+ type Age = IntRange<0, 120>;
21
+ //=> 0 | 1 | 2 | ... | 119
22
+
23
+ type FontSize = IntRange<10, 20>;
24
+ //=> 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19
25
+
26
+ type EvenNumber = IntRange<0, 11, 2>;
27
+ //=> 0 | 2 | 4 | 6 | 8 | 10
28
+ ```
29
+
20
30
  2. This can be used to define random numbers in a range. For example, `type RandomNumber = IntRange<0, 100>;`
21
31
 
22
32
  @example
23
33
  ```
24
34
  import type {IntRange} from 'type-fest';
25
35
 
26
- // Create union type `0 | 1 | ... | 9`
27
36
  type ZeroToNine = IntRange<0, 10>;
37
+ //=> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
28
38
 
29
- // Create union type `100 | 200 | 300 | ... | 900`
30
39
  type Hundreds = IntRange<100, 901, 100>;
40
+ //=> 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
31
41
  ```
32
42
 
33
43
  @see {@link IntClosedRange}
@@ -65,13 +65,13 @@ Set the given array to readonly if `IsReadonly` is `true`, otherwise set the giv
65
65
 
66
66
  @example
67
67
  ```
68
- type ReadonlyArray = readonly string[];
69
- type NormalArray = string[];
68
+ type ReadonlyStringArray = readonly string[];
69
+ type NormalStringArray = string[];
70
70
 
71
- type ReadonlyResult = SetArrayAccess<NormalArray, true>;
71
+ type ReadonlyResult = SetArrayAccess<NormalStringArray, true>;
72
72
  //=> readonly string[]
73
73
 
74
- type NormalResult = SetArrayAccess<ReadonlyArray, false>;
74
+ type NormalResult = SetArrayAccess<ReadonlyStringArray, false>;
75
75
  //=> string[]
76
76
  ```
77
77
  */
@@ -9,13 +9,13 @@ Returns the absolute value of a given value.
9
9
 
10
10
  @example
11
11
  ```
12
- NumberAbsolute<-1>;
12
+ type A = NumberAbsolute<-1>;
13
13
  //=> 1
14
14
 
15
- NumberAbsolute<1>;
15
+ type B = NumberAbsolute<1>;
16
16
  //=> 1
17
17
 
18
- NumberAbsolute<NegativeInfinity>
18
+ type C = NumberAbsolute<NegativeInfinity>;
19
19
  //=> PositiveInfinity
20
20
  ```
21
21
  */
@@ -126,16 +126,16 @@ Returns the number with reversed sign.
126
126
 
127
127
  @example
128
128
  ```
129
- ReverseSign<-1>;
129
+ type A = ReverseSign<-1>;
130
130
  //=> 1
131
131
 
132
- ReverseSign<1>;
132
+ type B = ReverseSign<1>;
133
133
  //=> -1
134
134
 
135
- ReverseSign<NegativeInfinity>
135
+ type C = ReverseSign<NegativeInfinity>;
136
136
  //=> PositiveInfinity
137
137
 
138
- ReverseSign<PositiveInfinity>
138
+ type D = ReverseSign<PositiveInfinity>;
139
139
  //=> NegativeInfinity
140
140
  ```
141
141
  */
@@ -1,5 +1,4 @@
1
1
  import type {Simplify} from '../simplify.d.ts';
2
- import type {UnknownArray} from '../unknown-array.d.ts';
3
2
  import type {IsEqual} from '../is-equal.d.ts';
4
3
  import type {KeysOfUnion} from '../keys-of-union.d.ts';
5
4
  import type {RequiredKeysOf} from '../required-keys-of.d.ts';
@@ -9,7 +8,7 @@ import type {IsAny} from '../is-any.d.ts';
9
8
  import type {If} from '../if.d.ts';
10
9
  import type {IsNever} from '../is-never.d.ts';
11
10
  import type {FilterDefinedKeys, FilterOptionalKeys} from './keys.d.ts';
12
- import type {NonRecursiveType} from './type.d.ts';
11
+ import type {MapsSetsOrArrays, NonRecursiveType} from './type.d.ts';
13
12
  import type {ToString} from './string.d.ts';
14
13
 
15
14
  /**
@@ -40,11 +39,13 @@ export type BuildObject<Key extends PropertyKey, Value, CopiedFrom extends objec
40
39
  Returns a boolean for whether the given type is a plain key-value object.
41
40
  */
42
41
  export type IsPlainObject<T> =
43
- T extends NonRecursiveType | UnknownArray | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>
42
+ IsNever<T> extends true
44
43
  ? false
45
- : T extends object
46
- ? true
47
- : false;
44
+ : T extends NonRecursiveType | MapsSetsOrArrays
45
+ ? false
46
+ : T extends object
47
+ ? true
48
+ : false;
48
49
 
49
50
  /**
50
51
  Extract the object field type if T is an object and K is a key of T, return `never` otherwise.
@@ -135,7 +136,7 @@ Extract all possible values for a given key from a union of object types.
135
136
 
136
137
  @example
137
138
  ```
138
- type Statuses = ValueOfUnion<{ id: 1, status: "open" } | { id: 2, status: "closed" }, "status">;
139
+ type Statuses = ValueOfUnion<{id: 1; status: 'open'} | {id: 2; status: 'closed'}, 'status'>;
139
140
  //=> "open" | "closed"
140
141
  ```
141
142
  */
@@ -148,14 +149,14 @@ Extract all readonly keys from a union of object types.
148
149
  @example
149
150
  ```
150
151
  type User = {
151
- readonly id: string;
152
- name: string;
152
+ readonly id: string;
153
+ name: string;
153
154
  };
154
155
 
155
156
  type Post = {
156
- readonly id: string;
157
- readonly author: string;
158
- body: string;
157
+ readonly id: string;
158
+ readonly author: string;
159
+ body: string;
159
160
  };
160
161
 
161
162
  type ReadonlyKeys = ReadonlyKeysOfUnion<User | Post>;