type-fest 5.5.0 → 5.6.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 (82) hide show
  1. package/index.d.ts +3 -0
  2. package/package.json +6 -4
  3. package/readme.md +70 -55
  4. package/source/absolute.d.ts +52 -0
  5. package/source/all-union-fields.d.ts +18 -18
  6. package/source/and.d.ts +1 -1
  7. package/source/array-splice.d.ts +24 -24
  8. package/source/camel-case.d.ts +38 -5
  9. package/source/camel-cased-properties-deep.d.ts +11 -4
  10. package/source/camel-cased-properties.d.ts +5 -1
  11. package/source/delimiter-case.d.ts +1 -0
  12. package/source/delimiter-cased-properties-deep.d.ts +8 -1
  13. package/source/delimiter-cased-properties.d.ts +5 -1
  14. package/source/empty-object.d.ts +1 -1
  15. package/source/entries.d.ts +1 -1
  16. package/source/entry.d.ts +1 -1
  17. package/source/get.d.ts +1 -1
  18. package/source/greater-than.d.ts +3 -2
  19. package/source/has-optional-keys.d.ts +1 -1
  20. package/source/has-readonly-keys.d.ts +1 -1
  21. package/source/has-required-keys.d.ts +1 -1
  22. package/source/has-writable-keys.d.ts +1 -1
  23. package/source/int-closed-range.d.ts +1 -3
  24. package/source/int-range.d.ts +3 -5
  25. package/source/internal/array.d.ts +7 -7
  26. package/source/internal/keys.d.ts +9 -9
  27. package/source/internal/numeric.d.ts +13 -23
  28. package/source/internal/tuple.d.ts +2 -2
  29. package/source/is-integer.d.ts +8 -8
  30. package/source/is-literal.d.ts +5 -5
  31. package/source/is-union.d.ts +12 -12
  32. package/source/iterable-element.d.ts +5 -5
  33. package/source/jsonify.d.ts +4 -4
  34. package/source/kebab-case.d.ts +1 -0
  35. package/source/kebab-cased-properties-deep.d.ts +7 -0
  36. package/source/kebab-cased-properties.d.ts +5 -1
  37. package/source/keys-of-union.d.ts +2 -2
  38. package/source/less-than-or-equal.d.ts +1 -1
  39. package/source/literal-to-primitive.d.ts +1 -1
  40. package/source/literal-union.d.ts +1 -1
  41. package/source/merge-exclusive.d.ts +3 -3
  42. package/source/multidimensional-array.d.ts +1 -1
  43. package/source/multidimensional-readonly-array.d.ts +1 -1
  44. package/source/non-nullable-deep.d.ts +102 -0
  45. package/source/numeric.d.ts +3 -3
  46. package/source/omit-deep.d.ts +22 -22
  47. package/source/or.d.ts +1 -1
  48. package/source/package-json.d.ts +7 -7
  49. package/source/partial-deep.d.ts +3 -1
  50. package/source/pascal-case.d.ts +1 -0
  51. package/source/pascal-cased-properties-deep.d.ts +7 -0
  52. package/source/pascal-cased-properties.d.ts +5 -1
  53. package/source/pick-deep.d.ts +2 -0
  54. package/source/readonly-deep.d.ts +5 -3
  55. package/source/remove-prefix.d.ts +15 -15
  56. package/source/replace.d.ts +2 -2
  57. package/source/require-all-or-none.d.ts +1 -1
  58. package/source/require-at-least-one.d.ts +5 -7
  59. package/source/require-exactly-one.d.ts +3 -3
  60. package/source/require-one-or-none.d.ts +1 -1
  61. package/source/required-deep.d.ts +3 -1
  62. package/source/screaming-snake-case.d.ts +1 -0
  63. package/source/set-non-nullable-deep.d.ts +6 -3
  64. package/source/set-non-nullable.d.ts +1 -1
  65. package/source/set-optional.d.ts +5 -5
  66. package/source/set-readonly.d.ts +3 -3
  67. package/source/set-required-deep.d.ts +1 -1
  68. package/source/set-required.d.ts +3 -3
  69. package/source/shared-union-fields.d.ts +9 -9
  70. package/source/snake-case.d.ts +1 -0
  71. package/source/snake-cased-properties-deep.d.ts +7 -0
  72. package/source/snake-cased-properties.d.ts +5 -1
  73. package/source/subtract.d.ts +4 -3
  74. package/source/sum.d.ts +5 -4
  75. package/source/tagged.d.ts +3 -5
  76. package/source/tsconfig-json.d.ts +39 -7
  77. package/source/union-length.d.ts +27 -0
  78. package/source/union-to-intersection.d.ts +1 -1
  79. package/source/union-to-tuple.d.ts +8 -4
  80. package/source/words.d.ts +30 -4
  81. package/source/writable.d.ts +14 -14
  82. package/source/xor.d.ts +1 -1
@@ -4,7 +4,7 @@ import type {UnknownArray} from './unknown-array.d.ts';
4
4
  import type {WordsOptions} from './words.d.ts';
5
5
 
6
6
  /**
7
- Convert object properties to delimiter case recursively.
7
+ Convert object properties to a custom string delimiter casing recursively.
8
8
 
9
9
  This can be useful when, for example, converting some API types from a different style.
10
10
 
@@ -51,6 +51,13 @@ const splitOnNumbers: DelimiterCasedPropertiesDeep<{line1: {line2: [{line3: stri
51
51
  ],
52
52
  },
53
53
  };
54
+
55
+ const splitOnPunctuation: DelimiterCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, '-', {splitOnPunctuation: true}> = {
56
+ 'user-info': {
57
+ 'user-id': 1,
58
+ 'user-name': 'Tom',
59
+ },
60
+ };
54
61
  ```
55
62
 
56
63
  @category Change case
@@ -3,7 +3,7 @@ import type {ApplyDefaultOptions} from './internal/index.d.ts';
3
3
  import type {WordsOptions} from './words.d.ts';
4
4
 
5
5
  /**
6
- Convert object properties to delimiter case but not recursively.
6
+ Convert object properties to a custom string delimiter casing.
7
7
 
8
8
  This can be useful when, for example, converting some API types from a different style.
9
9
 
@@ -27,6 +27,10 @@ const result: DelimiterCasedProperties<User, '-'> = {
27
27
  const splitOnNumbers: DelimiterCasedProperties<{line1: string}, '-', {splitOnNumbers: true}> = {
28
28
  'line-1': 'string',
29
29
  };
30
+
31
+ const splitOnPunctuation: DelimiterCasedProperties<{'foo::bar': string}, '-', {splitOnPunctuation: true}> = {
32
+ 'foo-bar': 'string',
33
+ };
30
34
  ```
31
35
 
32
36
  @category Change case
@@ -32,7 +32,7 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
32
32
  export type EmptyObject = {[emptyObjectSymbol]?: never};
33
33
 
34
34
  /**
35
- Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value.
35
+ Returns a boolean for whether the type is strictly equal to an empty plain object, the `{}` value.
36
36
 
37
37
  @example
38
38
  ```
@@ -6,7 +6,7 @@ type ObjectEntries<BaseType> = Array<_ObjectEntry<BaseType>>;
6
6
  type SetEntries<BaseType extends Set<unknown>> = Array<_SetEntry<BaseType>>;
7
7
 
8
8
  /**
9
- Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entries` type will return the type of that collection's entries.
9
+ Create a type that describes the key-value pairs produced when calling a collections `entries` method.
10
10
 
11
11
  For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
12
12
 
package/source/entry.d.ts CHANGED
@@ -7,7 +7,7 @@ export type _ObjectEntry<BaseType> = [keyof BaseType, BaseType[keyof BaseType]];
7
7
  export type _SetEntry<BaseType> = BaseType extends Set<infer ItemType> ? [ItemType, ItemType] : never;
8
8
 
9
9
  /**
10
- Many collections have an `entries` method which returns an array of a given object's own enumerable string-keyed property [key, value] pairs. The `Entry` type will return the type of that collection's entry.
10
+ Create a type that describes a single key-value pair produced when calling a collections `entries` method.
11
11
 
12
12
  For example the {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries|`Object`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/entries|`Map`}, {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries|`Array`}, and {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/entries|`Set`} collections all have this method. Note that `WeakMap` and `WeakSet` do not have this method since their entries are not enumerable.
13
13
 
package/source/get.d.ts CHANGED
@@ -161,7 +161,7 @@ type PropertyOf<BaseType, Key extends string, Options extends Required<GetOption
161
161
 
162
162
  // This works by first splitting the path based on `.` and `[...]` characters into a tuple of string keys. Then it recursively uses the head key to get the next property of the current object, until there are no keys left. Number keys extract the item type from arrays, or are converted to strings to extract types from tuples and dictionaries with number keys.
163
163
  /**
164
- Get a deeply-nested property from an object using a key path, like Lodash's `.get()` function.
164
+ Get a deeply-nested property from an object using a key path, like [Lodash's `.get()`](https://lodash.com/docs/latest#get) function.
165
165
 
166
166
  Use-case: Retrieve a property from deep inside an API response or some other complex object.
167
167
 
@@ -1,8 +1,9 @@
1
- import type {NumberAbsolute, PositiveNumericStringGt} from './internal/index.d.ts';
1
+ import type {PositiveNumericStringGt} from './internal/index.d.ts';
2
2
  import type {IsEqual} from './is-equal.d.ts';
3
3
  import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric.d.ts';
4
4
  import type {And} from './and.d.ts';
5
5
  import type {Or} from './or.d.ts';
6
+ import type {Absolute} from './absolute.d.ts';
6
7
 
7
8
  /**
8
9
  Returns a boolean for whether a given number is greater than another number.
@@ -82,7 +83,7 @@ export type GreaterThan<A extends number, B extends number> =
82
83
  ? true
83
84
  : [false, false] extends R
84
85
  ? PositiveNumericStringGt<`${A}`, `${B}`>
85
- : PositiveNumericStringGt<`${NumberAbsolute<B>}`, `${NumberAbsolute<A>}`>
86
+ : PositiveNumericStringGt<`${Absolute<B>}`, `${Absolute<A>}`>
86
87
  : never
87
88
  : never
88
89
  : never // Should never happen
@@ -1,7 +1,7 @@
1
1
  import type {OptionalKeysOf} from './optional-keys-of.d.ts';
2
2
 
3
3
  /**
4
- Creates a type that represents `true` or `false` depending on whether the given type has any optional fields.
4
+ Returns a boolean for whether the given type has any optional fields.
5
5
 
6
6
  This is useful when you want to create an API whose behavior depends on the presence or absence of optional fields.
7
7
 
@@ -1,7 +1,7 @@
1
1
  import type {ReadonlyKeysOf} from './readonly-keys-of.d.ts';
2
2
 
3
3
  /**
4
- Creates a type that represents `true` or `false` depending on whether the given type has any readonly fields.
4
+ Returns a boolean for whether the given type has any readonly fields.
5
5
 
6
6
  This is useful when you want to create an API whose behavior depends on the presence or absence of readonly fields.
7
7
 
@@ -1,7 +1,7 @@
1
1
  import type {RequiredKeysOf} from './required-keys-of.d.ts';
2
2
 
3
3
  /**
4
- Creates a type that represents `true` or `false` depending on whether the given type has any required fields.
4
+ Returns a boolean for whether the given type has any required fields.
5
5
 
6
6
  This is useful when you want to create an API whose behavior depends on the presence or absence of required fields.
7
7
 
@@ -1,7 +1,7 @@
1
1
  import type {WritableKeysOf} from './writable-keys-of.d.ts';
2
2
 
3
3
  /**
4
- Creates a type that represents `true` or `false` depending on whether the given type has any writable fields.
4
+ Returns a boolean for whether the given type has any writable fields.
5
5
 
6
6
  This is useful when you want to create an API whose behavior depends on the presence or absence of writable fields.
7
7
 
@@ -2,9 +2,7 @@ import type {IntRange} from './int-range.d.ts';
2
2
  import type {Sum} from './sum.d.ts';
3
3
 
4
4
  /**
5
- Generate a union of numbers.
6
-
7
- The numbers are created from the given `Start` (inclusive) parameter to the given `End` (inclusive) parameter.
5
+ Generate a union of numbers between a specified start and end (both inclusive), with an optional step.
8
6
 
9
7
  You skip over numbers using the `Step` parameter (defaults to `1`). For example, `IntClosedRange<0, 10, 2>` will create a union of `0 | 2 | 4 | 6 | 8 | 10`.
10
8
 
@@ -2,9 +2,7 @@ import type {TupleOf} from './tuple-of.d.ts';
2
2
  import type {Subtract} from './subtract.d.ts';
3
3
 
4
4
  /**
5
- Generate a union of numbers.
6
-
7
- The numbers are created from the given `Start` (inclusive) parameter to the given `End` (exclusive) parameter.
5
+ Generate a union of numbers between a specified start (inclusive) and end (exclusive), with an optional step.
8
6
 
9
7
  You skip over numbers using the `Step` parameter (defaults to `1`). For example, `IntRange<0, 10, 2>` will create a union of `0 | 2 | 4 | 6 | 8`.
10
8
 
@@ -56,9 +54,9 @@ type PrivateIntRange<
56
54
  // The final `List` is `[...StartLengthTuple, ...[number, ...GapLengthTuple], ...[number, ...GapLengthTuple], ... ...]`, so can initialize the `List` with `[...StartLengthTuple]`
57
55
  List extends unknown[] = TupleOf<Start, never>,
58
56
  EndLengthTuple extends unknown[] = TupleOf<End>,
59
- > = Gap extends 0 ?
57
+ > = Gap extends 0
60
58
  // Handle the case that without `Step`
61
- List['length'] extends End // The result of "List[length] === End"
59
+ ? List['length'] extends End // The result of "List[length] === End"
62
60
  ? Exclude<List[number], never> // All unused elements are `never`, so exclude them
63
61
  : PrivateIntRange<Start, End, Step, Gap, [...List, List['length'] ]>
64
62
  // Handle the case that with `Step`
@@ -29,8 +29,8 @@ type B = StaticPartOfArray<A>;
29
29
  */
30
30
  export type StaticPartOfArray<T extends UnknownArray, Result extends UnknownArray = []> =
31
31
  T extends unknown
32
- ? number extends T['length'] ?
33
- T extends readonly [infer U, ...infer V]
32
+ ? number extends T['length']
33
+ ? T extends readonly [infer U, ...infer V]
34
34
  ? StaticPartOfArray<V, [...Result, U]>
35
35
  : Result
36
36
  : T
@@ -69,11 +69,11 @@ type NormalResult = SetArrayAccess<ReadonlyStringArray, false>;
69
69
  ```
70
70
  */
71
71
  export type SetArrayAccess<T extends UnknownArray, IsReadonly extends boolean> =
72
- T extends readonly [...infer U] ?
73
- IsReadonly extends true
74
- ? readonly [...U]
75
- : [...U]
76
- : T;
72
+ T extends readonly [...infer U]
73
+ ? IsReadonly extends true
74
+ ? readonly [...U]
75
+ : [...U]
76
+ : T;
77
77
 
78
78
  /**
79
79
  Returns whether the given array `T` is readonly.
@@ -87,14 +87,14 @@ type Key4 = ExactKey<Object, 1>;
87
87
  @category Object
88
88
  */
89
89
  export type ExactKey<T extends object, Key extends PropertyKey> =
90
- Key extends keyof T
91
- ? Key
92
- : ToString<Key> extends keyof T
93
- ? ToString<Key>
94
- : Key extends `${infer NumberKey extends number}`
95
- ? NumberKey extends keyof T
96
- ? NumberKey
97
- : never
98
- : never;
90
+ Key extends keyof T
91
+ ? Key
92
+ : ToString<Key> extends keyof T
93
+ ? ToString<Key>
94
+ : Key extends `${infer NumberKey extends number}`
95
+ ? NumberKey extends keyof T
96
+ ? NumberKey
97
+ : never
98
+ : never;
99
99
 
100
100
  export {};
@@ -1,26 +1,8 @@
1
1
  import type {IsNever} from '../is-never.d.ts';
2
2
  import type {Finite, NegativeInfinity, PositiveInfinity} from '../numeric.d.ts';
3
3
  import type {UnknownArray} from '../unknown-array.d.ts';
4
- import type {StringToNumber} from './string.d.ts';
5
4
  import type {IfNotAnyOrNever, IsAnyOrNever} from './type.d.ts';
6
5
 
7
- /**
8
- Returns the absolute value of a given value.
9
-
10
- @example
11
- ```
12
- type A = NumberAbsolute<-1>;
13
- //=> 1
14
-
15
- type B = NumberAbsolute<1>;
16
- //=> 1
17
-
18
- type C = NumberAbsolute<NegativeInfinity>;
19
- //=> PositiveInfinity
20
- ```
21
- */
22
- export type NumberAbsolute<N extends number> = `${N}` extends `-${infer StringPositiveN}` ? StringToNumber<StringPositiveN> : N;
23
-
24
6
  /**
25
7
  Check whether the given type is a number or a number string.
26
8
 
@@ -142,10 +124,18 @@ type D = ReverseSign<PositiveInfinity>;
142
124
  */
143
125
  export type ReverseSign<N extends number> =
144
126
  // Handle edge cases
145
- N extends 0 ? 0 : N extends PositiveInfinity ? NegativeInfinity : N extends NegativeInfinity ? PositiveInfinity :
146
- // Handle negative numbers
147
- `${N}` extends `-${infer P extends number}` ? P
148
- // Handle positive numbers
149
- : `-${N}` extends `${infer R extends number}` ? R : never;
127
+ N extends 0
128
+ ? 0
129
+ : N extends PositiveInfinity
130
+ ? NegativeInfinity
131
+ : N extends NegativeInfinity
132
+ ? PositiveInfinity
133
+ // Handle negative numbers
134
+ : `${N}` extends `-${infer P extends number}`
135
+ ? P
136
+ // Handle positive numbers
137
+ : `-${N}` extends `${infer R extends number}`
138
+ ? R
139
+ : never;
150
140
 
151
141
  export {};
@@ -46,8 +46,8 @@ type B = TupleMax<[1, 2, 5, 3, 99, -1]>;
46
46
  ```
47
47
  */
48
48
  export type TupleMax<A extends number[], Result extends number = NegativeInfinity> = number extends A[number]
49
- ? never :
50
- A extends [infer F extends number, ...infer R extends number[]]
49
+ ? never
50
+ : A extends [infer F extends number, ...infer R extends number[]]
51
51
  ? GreaterThan<F, Result> extends true
52
52
  ? TupleMax<R, F>
53
53
  : TupleMax<R, Result>
@@ -47,14 +47,14 @@ type J = IsInteger<1e-7>;
47
47
  @category Numeric
48
48
  */
49
49
  export type IsInteger<T> =
50
- T extends bigint
51
- ? true
52
- : T extends number
53
- ? number extends T
54
- ? false
55
- : T extends PositiveInfinity | NegativeInfinity
50
+ T extends bigint
51
+ ? true
52
+ : T extends number
53
+ ? number extends T
56
54
  ? false
57
- : Not<IsFloat<T>>
58
- : false;
55
+ : T extends PositiveInfinity | NegativeInfinity
56
+ ? false
57
+ : Not<IsFloat<T>>
58
+ : false;
59
59
 
60
60
  export {};
@@ -121,11 +121,11 @@ export type IsStringLiteral<S> = IfNotAnyOrNever<S,
121
121
  export type _IsStringLiteral<S> =
122
122
  // If `T` is an infinite string type (e.g., `on${string}`), `Record<T, never>` produces an index signature,
123
123
  // and since `{}` extends index signatures, the result becomes `false`.
124
- S extends string
125
- ? {} extends Record<S, never>
126
- ? false
127
- : true
128
- : false;
124
+ S extends string
125
+ ? {} extends Record<S, never>
126
+ ? false
127
+ : true
128
+ : false;
129
129
 
130
130
  /**
131
131
  Returns a boolean for whether the given type is a `number` or `bigint` [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types).
@@ -21,20 +21,20 @@ export type IsUnion<T> = InternalIsUnion<T>;
21
21
  The actual implementation of `IsUnion`.
22
22
  */
23
23
  type InternalIsUnion<T, U = T> =
24
- (
25
- IsNever<T> extends true
26
- ? false
27
- : T extends any
28
- ? IsEqual<U, T> extends true
29
- ? false
30
- : true
31
- : never
32
- ) extends infer Result
24
+ (
25
+ IsNever<T> extends true
26
+ ? false
27
+ : T extends any
28
+ ? IsEqual<U, T> extends true
29
+ ? false
30
+ : true
31
+ : never
32
+ ) extends infer Result
33
33
  // In some cases `Result` will return `false | true` which is `boolean`,
34
34
  // that means `T` has at least two types and it's a union type,
35
35
  // so we will return `true` instead of `boolean`.
36
- ? boolean extends Result ? true
37
- : Result
38
- : never; // Should never happen
36
+ ? boolean extends Result ? true
37
+ : Result
38
+ : never; // Should never happen
39
39
 
40
40
  export {};
@@ -57,10 +57,10 @@ type Fruit = IterableElement<typeof fruits>;
57
57
  @category Iterable
58
58
  */
59
59
  export type IterableElement<TargetIterable> =
60
- TargetIterable extends Iterable<infer ElementType> ?
61
- ElementType :
62
- TargetIterable extends AsyncIterable<infer ElementType> ?
63
- ElementType :
64
- never;
60
+ TargetIterable extends Iterable<infer ElementType>
61
+ ? ElementType
62
+ : TargetIterable extends AsyncIterable<infer ElementType>
63
+ ? ElementType
64
+ : never;
65
65
 
66
66
  export {};
@@ -98,13 +98,13 @@ export type Jsonify<T> = IsAny<T> extends true
98
98
  ? null
99
99
  : T extends JsonPrimitive
100
100
  ? T
101
- : // Any object with toJSON is special case
102
- T extends {toJSON(): infer J}
101
+ // Any object with toJSON is special case
102
+ : T extends {toJSON(): infer J}
103
103
  ? (() => J) extends () => JsonValue // Is J assignable to JsonValue?
104
104
  ? J // Then T is Jsonable and its Jsonable value is J
105
105
  : Jsonify<J> // Maybe if we look a level deeper we'll find a JsonValue
106
- : // Instanced primitives are objects
107
- T extends Number
106
+ // Instanced primitives are objects
107
+ : T extends Number
108
108
  ? number
109
109
  : T extends String
110
110
  ? string
@@ -15,6 +15,7 @@ import type {KebabCase} from 'type-fest';
15
15
 
16
16
  const someVariable: KebabCase<'fooBar'> = 'foo-bar';
17
17
  const someVariableNoSplitOnNumbers: KebabCase<'p2pNetwork', {splitOnNumbers: false}> = 'p2p-network';
18
+ const someVariableWithPunctuation: KebabCase<'div.card::after', {splitOnPunctuation: true}> = 'div-card-after';
18
19
 
19
20
  // Advanced
20
21
 
@@ -51,6 +51,13 @@ const splitOnNumbers: KebabCasedPropertiesDeep<{line1: {line2: [{line3: string}]
51
51
  ],
52
52
  },
53
53
  };
54
+
55
+ const splitOnPunctuation: KebabCasedPropertiesDeep<{'user@info': {'user::id': number; 'user::name': string}}, {splitOnPunctuation: true}> = {
56
+ 'user-info': {
57
+ 'user-id': 1,
58
+ 'user-name': 'Tom',
59
+ },
60
+ };
54
61
  ```
55
62
 
56
63
  @category Change case
@@ -4,7 +4,7 @@ import type {ApplyDefaultOptions} from './internal/index.d.ts';
4
4
  import type {WordsOptions} from './words.d.ts';
5
5
 
6
6
  /**
7
- Convert object properties to kebab case but not recursively.
7
+ Convert top-level object properties to kebab case.
8
8
 
9
9
  This can be useful when, for example, converting some API types from a different style.
10
10
 
@@ -28,6 +28,10 @@ const result: KebabCasedProperties<User> = {
28
28
  const splitOnNumbers: KebabCasedProperties<{line1: string}, {splitOnNumbers: true}> = {
29
29
  'line-1': 'string',
30
30
  };
31
+
32
+ const splitOnPunctuation: KebabCasedProperties<{'foo::bar': string}, {splitOnPunctuation: true}> = {
33
+ 'foo-bar': 'string',
34
+ };
31
35
  ```
32
36
 
33
37
  @category Change case
@@ -38,7 +38,7 @@ type AllKeys = KeysOfUnion<Union>;
38
38
  @category Object
39
39
  */
40
40
  export type KeysOfUnion<ObjectType> =
41
- // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
42
- keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
41
+ // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
42
+ keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
43
43
 
44
44
  export {};
@@ -1,7 +1,7 @@
1
1
  import type {GreaterThan} from './greater-than.d.ts';
2
2
 
3
3
  /**
4
- Returns a boolean for whether a given number is less than or equal to another number.
4
+ Returns a boolean for whether a given number is less than or equal to another number.
5
5
 
6
6
  @example
7
7
  ```
@@ -1,5 +1,5 @@
1
1
  /**
2
- Given a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) return the {@link Primitive | primitive type} it belongs to, or `never` if it's not a primitive.
2
+ Given a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) return the [primitive type](https://developer.mozilla.org/en-US/docs/Glossary/Primitive) it belongs to, or `never` if it's not a primitive.
3
3
 
4
4
  Use-case: Working with generic types that may be literal types.
5
5
 
@@ -3,7 +3,7 @@ import type {Primitive} from './primitive.d.ts';
3
3
  export type _LiteralStringUnion<T> = LiteralUnion<T, string>;
4
4
 
5
5
  /**
6
- Allows creating a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
6
+ Create a union type by combining primitive types and literal types without sacrificing auto-completion in IDEs for the literal type part of the union.
7
7
 
8
8
  Currently, when a union type of a primitive type is combined with literal types, TypeScript loses all information about the combined literals. Thus, when such type is used in an IDE with autocompletion, no suggestions are made for the declared literals.
9
9
 
@@ -38,8 +38,8 @@ exclusiveOptions = {exclusive1: true, exclusive2: 'hi'};
38
38
  @category Object
39
39
  */
40
40
  export type MergeExclusive<FirstType, SecondType> =
41
- (FirstType | SecondType) extends object ?
42
- (Without<FirstType, SecondType> & SecondType) | (Without<SecondType, FirstType> & FirstType) :
43
- FirstType | SecondType;
41
+ (FirstType | SecondType) extends object
42
+ ? (Without<FirstType, SecondType> & SecondType) | (Without<SecondType, FirstType> & FirstType)
43
+ : FirstType | SecondType;
44
44
 
45
45
  export {};
@@ -4,7 +4,7 @@ import type {IsEqual} from './is-equal.d.ts';
4
4
  type Recursive<T> = Array<Recursive<T>>;
5
5
 
6
6
  /**
7
- Creates a type that represents a multidimensional array of the given type and dimension.
7
+ Create a type that represents a multidimensional array of the given type and dimension.
8
8
 
9
9
  Use-cases:
10
10
  - Return a n-dimensional array from functions.
@@ -4,7 +4,7 @@ import type {IsEqual} from './is-equal.d.ts';
4
4
  type Recursive<T> = ReadonlyArray<Recursive<T>>;
5
5
 
6
6
  /**
7
- Creates a type that represents a multidimensional readonly array that of the given type and dimension.
7
+ Create a type that represents a multidimensional readonly array of the given type and dimension.
8
8
 
9
9
  Use-cases:
10
10
  - Return a n-dimensional array from functions.
@@ -0,0 +1,102 @@
1
+ import type {BuiltIns, HasMultipleCallSignatures} from './internal/type.d.ts';
2
+ import type {IsNever} from './is-never.d.ts';
3
+ import type {Simplify} from './simplify.d.ts';
4
+
5
+ /**
6
+ Recursively removes `null` and `undefined` from the specified type.
7
+
8
+ Use-cases:
9
+ - Normalizing data received from external sources where `null`/`undefined` have been cleaned.
10
+ - Creating non-nullable variants of deeply nested types.
11
+
12
+ NOTE: Optional modifiers (`?`) are not removed from properties. For example, `NonNullableDeep<{foo?: string | null | undefined}>` will result in `{foo?: string}`. To remove both optional modifiers and nullables, use {@link RequiredDeep} in conjunction with this type.
13
+
14
+ @example
15
+ ```
16
+ import type {NonNullableDeep} from 'type-fest';
17
+
18
+ type UserDraft = {
19
+ name: string | null;
20
+ address: {
21
+ city: string | undefined;
22
+ postalCode: string | null;
23
+ landmark?: string | undefined;
24
+ };
25
+ tags: Array<string | null>;
26
+ visits: Map<string | null, {
27
+ date: Date | null;
28
+ notes: Set<string | undefined>;
29
+ }>;
30
+ };
31
+
32
+ type User = NonNullableDeep<UserDraft>;
33
+ //=> {
34
+ // name: string;
35
+ // address: {
36
+ // city: string;
37
+ // postalCode: string;
38
+ // landmark?: string;
39
+ // };
40
+ // tags: string[];
41
+ // visits: Map<string, {
42
+ // date: Date;
43
+ // notes: Set<string>;
44
+ // }>;
45
+ // }
46
+ ```
47
+
48
+ @example
49
+ ```
50
+ import type {NonNullableDeep} from 'type-fest';
51
+
52
+ type ArrayExample = NonNullableDeep<[{a: number | undefined}, ...Array<{b: string | null}>]>;
53
+ //=> [{a: number}, ...{b: string}[]]
54
+
55
+ type MapExample = NonNullableDeep<{a: Map<{a: string | null}, {c: number | undefined}>}>;
56
+ //=> {a: Map<{a: string}, {c: number}>}
57
+
58
+ type SetExample = NonNullableDeep<Set<{a: string | null}> | null | undefined>;
59
+ //=> Set<{a: string}>
60
+
61
+ type PromiseExample = NonNullableDeep<{a: Promise<{b: string | null}>}>;
62
+ //=> {a: Promise<{b: string}>}
63
+
64
+ type FunctionExample = NonNullableDeep<(a: string | null) => number | undefined>;
65
+ //=> (a: string) => number
66
+ ```
67
+
68
+ @category Utilities
69
+ @category Object
70
+ @category Array
71
+ @category Set
72
+ @category Map
73
+ */
74
+ export type NonNullableDeep<T> =
75
+ T extends BuiltIns | (new (...arguments_: any[]) => unknown)
76
+ ? Exclude<T, null | undefined> // `Exclude` is used instead of `NonNullable` because `NonNullable<void>` results in `void & {}`.
77
+ : T extends Map<infer KeyType, infer ValueType>
78
+ ? Map<NonNullableDeep<KeyType>, NonNullableDeep<ValueType>>
79
+ : T extends Set<infer ItemType>
80
+ ? Set<NonNullableDeep<ItemType>>
81
+ : T extends ReadonlyMap<infer KeyType, infer ValueType>
82
+ ? ReadonlyMap<NonNullableDeep<KeyType>, NonNullableDeep<ValueType>>
83
+ : T extends ReadonlySet<infer ItemType>
84
+ ? ReadonlySet<NonNullableDeep<ItemType>>
85
+ : T extends WeakMap<infer KeyType, infer ValueType>
86
+ ? WeakMap<NonNullableDeep<KeyType>, NonNullableDeep<ValueType>>
87
+ : T extends WeakSet<infer ItemType>
88
+ ? WeakSet<NonNullableDeep<ItemType>>
89
+ : T extends Promise<infer ValueType>
90
+ ? Promise<NonNullableDeep<ValueType>>
91
+ : T extends (...arguments_: any[]) => unknown
92
+ ? HasMultipleCallSignatures<T> extends true
93
+ ? T
94
+ : ((...arguments_: NonNullableDeep<Parameters<T>>) => NonNullableDeep<ReturnType<T>>)
95
+ & (IsNever<keyof T> extends true
96
+ ? unknown
97
+ : NonNullableDeep<Simplify<T>>) // `Simplify` removes the call signature
98
+ : T extends object
99
+ ? {[P in keyof T]: NonNullableDeep<T[P]>}
100
+ : unknown;
101
+
102
+ export {};