type-fest 5.3.1 → 5.4.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 (53) hide show
  1. package/index.d.ts +3 -0
  2. package/package.json +4 -4
  3. package/readme.md +5 -0
  4. package/source/all-extend.d.ts +9 -6
  5. package/source/array-reverse.d.ts +84 -0
  6. package/source/array-slice.d.ts +1 -1
  7. package/source/array-splice.d.ts +3 -3
  8. package/source/conditional-pick-deep.d.ts +1 -1
  9. package/source/conditional-simplify-deep.d.ts +3 -3
  10. package/source/distributed-omit.d.ts +4 -4
  11. package/source/distributed-pick.d.ts +5 -5
  12. package/source/exact.d.ts +1 -1
  13. package/source/except.d.ts +5 -5
  14. package/source/exclusify-union.d.ts +41 -7
  15. package/source/fixed-length-array.d.ts +6 -6
  16. package/source/get.d.ts +9 -3
  17. package/source/int-closed-range.d.ts +2 -2
  18. package/source/int-range.d.ts +2 -2
  19. package/source/internal/object.d.ts +25 -1
  20. package/source/is-literal.d.ts +3 -2
  21. package/source/is-never.d.ts +2 -2
  22. package/source/is-unknown.d.ts +1 -1
  23. package/source/jsonifiable.d.ts +3 -5
  24. package/source/key-as-string.d.ts +1 -1
  25. package/source/merge-deep.d.ts +9 -9
  26. package/source/merge-exclusive.d.ts +3 -3
  27. package/source/merge.d.ts +4 -1
  28. package/source/non-empty-string.d.ts +3 -3
  29. package/source/non-empty-tuple.d.ts +2 -2
  30. package/source/numeric.d.ts +3 -3
  31. package/source/object-merge.d.ts +194 -0
  32. package/source/omit-deep.d.ts +6 -22
  33. package/source/omit-index-signature.d.ts +8 -4
  34. package/source/override-properties.d.ts +1 -1
  35. package/source/paths.d.ts +1 -1
  36. package/source/readonly-tuple.d.ts +2 -2
  37. package/source/required-deep.d.ts +2 -1
  38. package/source/schema.d.ts +10 -7
  39. package/source/set-non-nullable-deep.d.ts +1 -1
  40. package/source/set-parameter-type.d.ts +7 -7
  41. package/source/set-required-deep.d.ts +1 -7
  42. package/source/set-return-type.d.ts +1 -1
  43. package/source/split-on-rest-element.d.ts +2 -2
  44. package/source/subtract.d.ts +1 -1
  45. package/source/sum.d.ts +1 -1
  46. package/source/tuple-of.d.ts +1 -1
  47. package/source/tuple-to-object.d.ts +6 -6
  48. package/source/tuple-to-union.d.ts +1 -1
  49. package/source/union-to-intersection.d.ts +1 -1
  50. package/source/unknown-record.d.ts +6 -6
  51. package/source/unwrap-partial.d.ts +33 -0
  52. package/source/value-of.d.ts +2 -2
  53. package/source/words.d.ts +2 -2
@@ -13,27 +13,27 @@ Note: Tuple labels are [lost in the transformation process](https://stackoverflo
13
13
  import type {TupleToObject} from 'type-fest';
14
14
 
15
15
  type Example1 = TupleToObject<[number, string, boolean]>;
16
- //=> { 0: number; 1: string; 2: boolean }
16
+ //=> {0: number; 1: string; 2: boolean}
17
17
 
18
18
  // Tuples with optional indices
19
19
  type Example2 = TupleToObject<[number, string?, boolean?]>;
20
- //=> { 0: number; 1?: string; 2?: boolean }
20
+ //=> {0: number; 1?: string; 2?: boolean}
21
21
 
22
22
  // Readonly tuples
23
23
  type Example3 = TupleToObject<readonly [number, string?]>;
24
- //=> { readonly 0: number; readonly 1?: string }
24
+ //=> {readonly 0: number; readonly 1?: string}
25
25
 
26
26
  // Non-tuple arrays get transformed into index signatures
27
27
  type Example4 = TupleToObject<string[]>;
28
- //=> { [x: number]: string }
28
+ //=> {[x: number]: string}
29
29
 
30
30
  // Tuples with rest elements
31
31
  type Example5 = TupleToObject<[number, string, ...boolean[]]>;
32
- //=> { [x: number]: number | string | boolean; 0: number; 1: string }
32
+ //=> {[x: number]: string | number | boolean; 0: number; 1: string}
33
33
 
34
34
  // Tuple labels are not preserved
35
35
  type Example6 = TupleToObject<[x: number, y: number]>;
36
- //=> { 0: number; 1: number }
36
+ //=> {0: number; 1: number}
37
37
  ```
38
38
 
39
39
  @category Array
@@ -39,7 +39,7 @@ const erroringType = new Set(['a', 'b', 'c']);
39
39
 
40
40
  // @ts-expect-error
41
41
  type ErroringType = typeof erroringType[number];
42
- //=> Type 'Set<string>' has no matching index signature for type 'number'. ts(2537)
42
+ // Error: Type 'Set<string>' has no matching index signature for type 'number'. ts(2537)
43
43
 
44
44
  const numberBool: {[n: number]: boolean} = {1: true};
45
45
 
@@ -10,7 +10,7 @@ import type {UnionToIntersection} from 'type-fest';
10
10
  type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
11
11
 
12
12
  type Intersection = UnionToIntersection<Union>;
13
- //=> {the(): void; great(arg: string): void; escape: boolean};
13
+ //=> {the(): void} & {great(arg: string): void} & {escape: boolean}
14
14
  ```
15
15
 
16
16
  @category Type
@@ -11,18 +11,18 @@ function toJson(object: UnknownRecord) {
11
11
  return JSON.stringify(object);
12
12
  }
13
13
 
14
- toJson({hello: 'world'});
15
- //=> '{"hello":"world"}'
14
+ toJson({hello: 'world'}); // Ok
16
15
 
17
16
  function isObject(value: unknown): value is UnknownRecord {
18
17
  return typeof value === 'object' && value !== null;
19
18
  }
20
19
 
21
- isObject({hello: 'world'});
22
- //=> true
20
+ const value: unknown = {hello: 'world'};
23
21
 
24
- isObject('hello');
25
- //=> false
22
+ if (isObject(value)) {
23
+ const v = value;
24
+ //=> UnknownRecord
25
+ }
26
26
  ```
27
27
 
28
28
  @category Type
@@ -0,0 +1,33 @@
1
+ /**
2
+ Revert the `Partial` modifier on an object type.
3
+
4
+ Use-case: Infer the underlying type `T` when only `Partial<T>` is available or the original type may not be directly accessible.
5
+
6
+ @example
7
+ ```
8
+ import type {UnwrapPartial} from 'type-fest';
9
+
10
+ type Config = Partial<{
11
+ port: number;
12
+ host: string;
13
+ secure?: boolean;
14
+ }>;
15
+
16
+ type InitializedConfig = UnwrapPartial<Config>;
17
+ //=> {port: number; host: string; secure?: boolean}
18
+ ```
19
+
20
+ Note: If the provided type isn’t of `Partial<T>`, `UnwrapPartial` has no effect on the original type.
21
+
22
+ @category Object
23
+ */
24
+ export type UnwrapPartial<PartialObjectType> =
25
+ PartialObjectType extends Partial<infer ObjectType>
26
+ ? (
27
+ Partial<ObjectType> extends PartialObjectType
28
+ ? ObjectType
29
+ : PartialObjectType
30
+ )
31
+ : PartialObjectType;
32
+
33
+ export {};
@@ -8,13 +8,13 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438)
8
8
  import type {ValueOf} from 'type-fest';
9
9
 
10
10
  type A = ValueOf<{id: number; name: string; active: boolean}>;
11
- //=> number | string | boolean
11
+ //=> string | number | boolean
12
12
 
13
13
  type B = ValueOf<{id: number; name: string; active: boolean}, 'name'>;
14
14
  //=> string
15
15
 
16
16
  type C = ValueOf<{id: number; name: string; active: boolean}, 'id' | 'name'>;
17
- //=> number | string
17
+ //=> string | number
18
18
  ```
19
19
 
20
20
  @category Object
package/source/words.d.ts CHANGED
@@ -31,10 +31,10 @@ export type WordsOptions = {
31
31
  import type {Words} from 'type-fest';
32
32
 
33
33
  type Example1 = Words<'p2pNetwork', {splitOnNumbers: true}>;
34
- //=> ["p", "2", "p", "Network"]
34
+ //=> ['p', '2', 'p', 'Network']
35
35
 
36
36
  type Example2 = Words<'p2pNetwork', {splitOnNumbers: false}>;
37
- //=> ["p2p", "Network"]
37
+ //=> ['p2p', 'Network']
38
38
  ```
39
39
  */
40
40
  splitOnNumbers?: boolean;