type-fest 2.16.0 → 2.17.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.
package/index.d.ts CHANGED
@@ -14,7 +14,7 @@ export {RequireAtLeastOne} from './source/require-at-least-one';
14
14
  export {RequireExactlyOne} from './source/require-exactly-one';
15
15
  export {RequireAllOrNone} from './source/require-all-or-none';
16
16
  export {RemoveIndexSignature} from './source/remove-index-signature';
17
- export {PartialDeep} from './source/partial-deep';
17
+ export {PartialDeep, PartialDeepOptions} from './source/partial-deep';
18
18
  export {ReadonlyDeep} from './source/readonly-deep';
19
19
  export {LiteralUnion} from './source/literal-union';
20
20
  export {Promisable} from './source/promisable';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "2.16.0",
3
+ "version": "2.17.0",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
package/readme.md CHANGED
@@ -839,7 +839,7 @@ There are many advanced types most users don't know about.
839
839
  type T2 = Uppercase<'foo' | 'bar'>; // 'FOO' | 'BAR'
840
840
 
841
841
  type T3<S extends string> = Uppercase<`aB${S}`>;
842
- type T4 = T30<'xYz'>; // 'ABXYZ'
842
+ type T4 = T3<'xYz'>; // 'ABXYZ'
843
843
 
844
844
  type T5 = Uppercase<string>; // string
845
845
  type T6 = Uppercase<any>; // any
@@ -860,7 +860,7 @@ There are many advanced types most users don't know about.
860
860
  type T2 = Lowercase<'FOO' | 'BAR'>; // 'foo' | 'bar'
861
861
 
862
862
  type T3<S extends string> = Lowercase<`aB${S}`>;
863
- type T4 = T32<'xYz'>; // 'abxyz'
863
+ type T4 = T3<'xYz'>; // 'abxyz'
864
864
 
865
865
  type T5 = Lowercase<string>; // string
866
866
  type T6 = Lowercase<any>; // any
@@ -881,7 +881,7 @@ There are many advanced types most users don't know about.
881
881
  type T2 = Capitalize<'foo' | 'bar'>; // 'Foo' | 'Bar'
882
882
 
883
883
  type T3<S extends string> = Capitalize<`aB${S}`>;
884
- type T4 = T32<'xYz'>; // 'ABxYz'
884
+ type T4 = T3<'xYz'>; // 'ABxYz'
885
885
 
886
886
  type T5 = Capitalize<string>; // string
887
887
  type T6 = Capitalize<any>; // any
@@ -902,7 +902,7 @@ There are many advanced types most users don't know about.
902
902
  type T2 = Uncapitalize<'Foo' | 'Bar'>; // 'foo' | 'bar'
903
903
 
904
904
  type T3<S extends string> = Uncapitalize<`AB${S}`>;
905
- type T4 = T30<'xYz'>; // 'aBxYz'
905
+ type T4 = T3<'xYz'>; // 'aBxYz'
906
906
 
907
907
  type T5 = Uncapitalize<string>; // string
908
908
  type T6 = Uncapitalize<any>; // any
@@ -1,4 +1,4 @@
1
- import type {WordSeparators} from '../source/utilities';
1
+ import type {WordSeparators} from '../source/internal';
2
2
  import type {Split} from './split';
3
3
 
4
4
  /**
@@ -1,4 +1,4 @@
1
- import type {UpperCaseCharacters, WordSeparators} from '../source/utilities';
1
+ import type {UpperCaseCharacters, WordSeparators} from '../source/internal';
2
2
 
3
3
  /**
4
4
  Unlike a simpler split, this one includes the delimiter splitted on in the resulting array literal. This is to enable splitting on, for example, upper-case characters.
package/source/get.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type {StringDigit} from '../source/utilities';
1
+ import type {StringDigit} from '../source/internal';
2
2
  import type {Split} from './split';
3
3
  import type {StringKeyOf} from './string-key-of';
4
4
 
@@ -51,3 +51,9 @@ The reason a simple `keyof Union` does not work is because `keyof` always return
51
51
  @link https://stackoverflow.com/a/49402091
52
52
  */
53
53
  export type KeysOfUnion<T> = T extends T ? keyof T : never;
54
+
55
+ export type UpperCaseCharacters = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
56
+
57
+ export type WordSeparators = '-' | '_' | ' ';
58
+
59
+ export type StringDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
@@ -1,5 +1,17 @@
1
1
  import type {BuiltIns} from './internal';
2
2
 
3
+ /**
4
+ @see PartialDeep
5
+ */
6
+ export interface PartialDeepOptions {
7
+ /**
8
+ Whether to affect the individual elements of arrays and tuples.
9
+
10
+ @default true
11
+ */
12
+ readonly recurseIntoArrays?: boolean;
13
+ }
14
+
3
15
  /**
4
16
  Create a type from another type with all keys and nested keys set to optional.
5
17
 
@@ -28,54 +40,74 @@ const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
28
40
  settings = applySavedSettings({textEditor: {fontWeight: 500}});
29
41
  ```
30
42
 
43
+ By default, this also affects array and tuple types:
44
+
45
+ ```
46
+ import type {PartialDeep} from 'type-fest';
47
+
48
+ interface Settings {
49
+ languages: string[];
50
+ }
51
+
52
+ const partialSettings: PartialDeep<Settings> = {
53
+ languages: [undefined]
54
+ };
55
+ ```
56
+
57
+ If this is undesirable, you can pass `{recurseIntoArrays: false}` as the second type argument.
58
+
31
59
  @category Object
32
60
  @category Array
33
61
  @category Set
34
62
  @category Map
35
63
  */
36
- export type PartialDeep<T> = T extends BuiltIns
64
+ export type PartialDeep<T, Options extends PartialDeepOptions = {}> = T extends BuiltIns
37
65
  ? T
38
66
  : T extends Map<infer KeyType, infer ValueType>
39
- ? PartialMapDeep<KeyType, ValueType>
67
+ ? PartialMapDeep<KeyType, ValueType, Options>
40
68
  : T extends Set<infer ItemType>
41
- ? PartialSetDeep<ItemType>
69
+ ? PartialSetDeep<ItemType, Options>
42
70
  : T extends ReadonlyMap<infer KeyType, infer ValueType>
43
- ? PartialReadonlyMapDeep<KeyType, ValueType>
71
+ ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
44
72
  : T extends ReadonlySet<infer ItemType>
45
- ? PartialReadonlySetDeep<ItemType>
73
+ ? PartialReadonlySetDeep<ItemType, Options>
46
74
  : T extends ((...arguments: any[]) => unknown)
47
75
  ? T | undefined
48
76
  : T extends object
49
- ? T extends Array<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
50
- ? ItemType[] extends T // Test for arrays (non-tuples) specifically
51
- ? Array<PartialDeep<ItemType | undefined>> // Recreate relevant array type to prevent eager evaluation of circular reference
52
- : PartialObjectDeep<T> // Tuples behave properly
53
- : PartialObjectDeep<T>
77
+ ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
78
+ ? Options['recurseIntoArrays'] extends false // If they opt out of array testing, just use the original type
79
+ ? T
80
+ : ItemType[] extends T // Test for arrays (non-tuples) specifically
81
+ ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
82
+ ? ReadonlyArray<PartialDeep<ItemType | undefined, Options>>
83
+ : Array<PartialDeep<ItemType | undefined, Options>>
84
+ : PartialObjectDeep<T, Options> // Tuples behave properly
85
+ : PartialObjectDeep<T, Options>
54
86
  : unknown;
55
87
 
56
88
  /**
57
89
  Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
58
90
  */
59
- interface PartialMapDeep<KeyType, ValueType> extends Map<PartialDeep<KeyType>, PartialDeep<ValueType>> {}
91
+ interface PartialMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> extends Map<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>> {}
60
92
 
61
93
  /**
62
94
  Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
63
95
  */
64
- interface PartialSetDeep<T> extends Set<PartialDeep<T>> {}
96
+ interface PartialSetDeep<T, Options extends PartialDeepOptions> extends Set<PartialDeep<T, Options>> {}
65
97
 
66
98
  /**
67
99
  Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
68
100
  */
69
- interface PartialReadonlyMapDeep<KeyType, ValueType> extends ReadonlyMap<PartialDeep<KeyType>, PartialDeep<ValueType>> {}
101
+ interface PartialReadonlyMapDeep<KeyType, ValueType, Options extends PartialDeepOptions> extends ReadonlyMap<PartialDeep<KeyType, Options>, PartialDeep<ValueType, Options>> {}
70
102
 
71
103
  /**
72
104
  Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
73
105
  */
74
- interface PartialReadonlySetDeep<T> extends ReadonlySet<PartialDeep<T>> {}
106
+ interface PartialReadonlySetDeep<T, Options extends PartialDeepOptions> extends ReadonlySet<PartialDeep<T, Options>> {}
75
107
 
76
108
  /**
77
109
  Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
78
110
  */
79
- type PartialObjectDeep<ObjectType extends object> = {
80
- [KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType]>
111
+ type PartialObjectDeep<ObjectType extends object, Options extends PartialDeepOptions> = {
112
+ [KeyType in keyof ObjectType]?: PartialDeep<ObjectType[KeyType], Options>
81
113
  };
@@ -1,5 +0,0 @@
1
- export type UpperCaseCharacters = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z';
2
-
3
- export type WordSeparators = '-' | '_' | ' ';
4
-
5
- export type StringDigit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';