type-fest 2.7.0 → 2.8.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 (64) hide show
  1. package/index.d.ts +2 -0
  2. package/package.json +1 -1
  3. package/readme.md +35 -21
  4. package/source/async-return-type.d.ts +1 -1
  5. package/source/asyncify.d.ts +1 -1
  6. package/source/basic.d.ts +6 -6
  7. package/source/camel-case.d.ts +2 -1
  8. package/source/camel-cased-properties-deep.d.ts +3 -1
  9. package/source/camel-cased-properties.d.ts +3 -1
  10. package/source/conditional-except.d.ts +1 -1
  11. package/source/conditional-keys.d.ts +1 -1
  12. package/source/conditional-pick.d.ts +1 -1
  13. package/source/delimiter-case.d.ts +3 -2
  14. package/source/delimiter-cased-properties-deep.d.ts +3 -1
  15. package/source/delimiter-cased-properties.d.ts +3 -1
  16. package/source/entries.d.ts +4 -1
  17. package/source/entry.d.ts +4 -1
  18. package/source/except.d.ts +1 -1
  19. package/source/fixed-length-array.d.ts +1 -1
  20. package/source/get.d.ts +3 -1
  21. package/source/includes.d.ts +1 -1
  22. package/source/iterable-element.d.ts +1 -1
  23. package/source/join.d.ts +2 -1
  24. package/source/jsonify.d.ts +1 -1
  25. package/source/kebab-case.d.ts +2 -1
  26. package/source/kebab-cased-properties-deep.d.ts +3 -1
  27. package/source/kebab-cased-properties.d.ts +3 -1
  28. package/source/last-array-element.d.ts +2 -1
  29. package/source/literal-union.d.ts +1 -1
  30. package/source/merge-exclusive.d.ts +1 -1
  31. package/source/merge.d.ts +1 -1
  32. package/source/multidimensional-array.d.ts +1 -1
  33. package/source/multidimensional-readonly-array.d.ts +1 -1
  34. package/source/mutable.d.ts +1 -1
  35. package/source/numeric.d.ts +40 -8
  36. package/source/observable-like.d.ts +15 -1
  37. package/source/opaque.d.ts +1 -1
  38. package/source/package-json.d.ts +1 -1
  39. package/source/partial-deep.d.ts +4 -1
  40. package/source/pascal-case.d.ts +2 -1
  41. package/source/pascal-cased-properties-deep.d.ts +3 -1
  42. package/source/pascal-cased-properties.d.ts +3 -1
  43. package/source/primitive.d.ts +1 -1
  44. package/source/promisable.d.ts +2 -2
  45. package/source/promise-value.d.ts +1 -1
  46. package/source/readonly-deep.d.ts +4 -1
  47. package/source/require-all-or-none.d.ts +1 -1
  48. package/source/require-at-least-one.d.ts +1 -1
  49. package/source/require-exactly-one.d.ts +1 -1
  50. package/source/screaming-snake-case.d.ts +2 -1
  51. package/source/set-optional.d.ts +1 -1
  52. package/source/set-required.d.ts +1 -1
  53. package/source/set-return-type.d.ts +1 -1
  54. package/source/simplify.d.ts +1 -1
  55. package/source/snake-case.d.ts +2 -1
  56. package/source/snake-cased-properties-deep.d.ts +3 -1
  57. package/source/snake-cased-properties.d.ts +3 -1
  58. package/source/split.d.ts +2 -1
  59. package/source/stringified.d.ts +1 -1
  60. package/source/trim.d.ts +2 -1
  61. package/source/tsconfig-json.d.ts +1 -1
  62. package/source/typed-array.d.ts +1 -1
  63. package/source/union-to-intersection.d.ts +1 -1
  64. package/source/value-of.d.ts +1 -1
package/index.d.ts CHANGED
@@ -42,6 +42,8 @@ export {
42
42
  NegativeInfinity,
43
43
  Finite,
44
44
  Integer,
45
+ Float,
46
+ NegativeFloat,
45
47
  Negative,
46
48
  NonNegative,
47
49
  NegativeInteger,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "2.7.0",
3
+ "version": "2.8.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
@@ -106,38 +106,57 @@ Click the type names for complete docs.
106
106
  - [`PartialDeep`](source/partial-deep.d.ts) - Create a deeply optional version of another type. Use [`Partial<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype) if you only need one level deep.
107
107
  - [`ReadonlyDeep`](source/readonly-deep.d.ts) - Create a deeply immutable version of an `object`/`Map`/`Set`/`Array` type. Use [`Readonly<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype) if you only need one level deep.
108
108
  - [`LiteralUnion`](source/literal-union.d.ts) - 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. Workaround for [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729).
109
- - [`Promisable`](source/promisable.d.ts) - Create a type that represents either the value or the value wrapped in `PromiseLike`.
110
109
  - [`Opaque`](source/opaque.d.ts) - Create an [opaque type](https://codemix.com/opaque-types-in-javascript/).
111
110
  - [`SetOptional`](source/set-optional.d.ts) - Create a type that makes the given keys optional.
112
111
  - [`SetRequired`](source/set-required.d.ts) - Create a type that makes the given keys required.
113
112
  - [`ValueOf`](source/value-of.d.ts) - Create a union of the given object's values, and optionally specify which keys to get the values from.
114
- - [`AsyncReturnType`](source/async-return-type.d.ts) - Unwrap the return type of a function that returns a `Promise`.
115
113
  - [`ConditionalKeys`](source/conditional-keys.d.ts) - Extract keys from a shape where values extend the given `Condition` type.
116
114
  - [`ConditionalPick`](source/conditional-pick.d.ts) - Like `Pick` except it selects properties from a shape where the values extend the given `Condition` type.
117
115
  - [`ConditionalExcept`](source/conditional-except.d.ts) - Like `Omit` except it removes properties from a shape where the values extend the given `Condition` type.
118
116
  - [`UnionToIntersection`](source/union-to-intersection.d.ts) - Convert a union type to an intersection type.
119
117
  - [`Stringified`](source/stringified.d.ts) - Create a type with the keys of the given type changed to `string` type.
120
- - [`FixedLengthArray`](source/fixed-length-array.d.ts) - Create a type that represents an array of the given type and length.
121
- - [`MultidimensionalArray`](source/multidimensional-array.d.ts) - Create a type that represents a multidimensional array of the given type and dimensions.
122
- - [`MultidimensionalReadonlyArray`](source/multidimensional-readonly-array.d.ts) - Create a type that represents a multidimensional readonly array of the given type and dimensions.
123
118
  - [`IterableElement`](source/iterable-element.d.ts) - Get the element type of an `Iterable`/`AsyncIterable`. For example, an array or a generator.
124
119
  - [`Entry`](source/entry.d.ts) - Create a type that represents the type of an entry of a collection.
125
120
  - [`Entries`](source/entries.d.ts) - Create a type that represents the type of the entries of a collection.
126
121
  - [`SetReturnType`](source/set-return-type.d.ts) - Create a function type with a return type of your choice and the same parameters as the given function type.
127
- - [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type.
128
- - [`Includes`](source/includes.d.ts) - Returns a boolean for whether the given array includes the given item.
129
122
  - [`Simplify`](source/simplify.d.ts) - Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
130
123
  - [`Jsonify`](source/jsonify.d.ts) - Transform a type to one that is assignable to the `JsonValue` type.
131
- - [`PositiveInfinity`](source/numeric-range.d.ts) - Matches the hidden `Infinity` type.
132
- - [`NegativeInfinity`](source/numeric-range.d.ts) - Matches the hidden `-Infinity` type.
133
- - [`Finite`](source/numeric-range.d.ts) - A finite `number`.
134
- - [`Integer`](source/numeric-range.d.ts) - A `number` that is an integer.
135
- - [`Negative`](source/numeric-range.d.ts) - A negative `number`/`bigint` (`-∞ < x < 0`)
136
- - [`NonNegative`](source/numeric-range.d.ts) - A non-negative `number`/`bigint` (`0 <= x < ∞`).
137
- - [`NegativeInteger`](source/numeric-range.d.ts) - A negative (`-∞ < x < 0`) `number` that is an integer.
138
- - [`NonNegativeInteger`](source/numeric-range.d.ts) - A non-negative (`0 <= x < ∞`) `number` that is an integer.
124
+ - [`Get`](source/get.d.ts) - Get a deeply-nested property from an object using a key path, like [Lodash's `.get()`](https://lodash.com/docs/latest#get) function.
125
+
126
+ ### Async
127
+
128
+ - [`Promisable`](source/promisable.d.ts) - Create a type that represents either the value or the value wrapped in `PromiseLike`.
129
+ - [`AsyncReturnType`](source/async-return-type.d.ts) - Unwrap the return type of a function that returns a `Promise`.
130
+ - [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type.
131
+
132
+ ### String
133
+
134
+ - [`Trim`](source/trim.d.ts) - Remove leading and trailing spaces from a string.
135
+ - [`Split`](source/split.d.ts) - Represents an array of strings split using a given character or character set.
136
+
137
+ ### Array
138
+
139
+ - [`Includes`](source/includes.d.ts) - Returns a boolean for whether the given array includes the given item.
140
+ - [`Join`](source/join.d.ts) - Join an array of strings and/or numbers using the given string as a delimiter.
141
+ - [`LastArrayElement`](source/last-array-element.d.ts) - Extracts the type of the last element of an array.
142
+ - [`FixedLengthArray`](source/fixed-length-array.d.ts) - Create a type that represents an array of the given type and length.
143
+ - [`MultidimensionalArray`](source/multidimensional-array.d.ts) - Create a type that represents a multidimensional array of the given type and dimensions.
144
+ - [`MultidimensionalReadonlyArray`](source/multidimensional-readonly-array.d.ts) - Create a type that represents a multidimensional readonly array of the given type and dimensions.
145
+
146
+ ### Numeric
139
147
 
140
- ### Template literal types
148
+ - [`PositiveInfinity`](source/numeric.d.ts) - Matches the hidden `Infinity` type.
149
+ - [`NegativeInfinity`](source/numeric.d.ts) - Matches the hidden `-Infinity` type.
150
+ - [`Finite`](source/numeric.d.ts) - A finite `number`.
151
+ - [`Integer`](source/numeric.d.ts) - A `number` that is an integer.
152
+ - [`Float`](source/numeric.d.ts) - A `number` that is not an integer.
153
+ - [`NegativeFloat`](source/numeric.d.ts) - A negative (`-∞ < x < 0`) `number` that is not an integer.
154
+ - [`Negative`](source/numeric.d.ts) - A negative `number`/`bigint` (`-∞ < x < 0`)
155
+ - [`NonNegative`](source/numeric.d.ts) - A non-negative `number`/`bigint` (`0 <= x < ∞`).
156
+ - [`NegativeInteger`](source/numeric.d.ts) - A negative (`-∞ < x < 0`) `number` that is an integer.
157
+ - [`NonNegativeInteger`](source/numeric.d.ts) - A non-negative (`0 <= x < ∞`) `number` that is an integer.
158
+
159
+ ### Change case
141
160
 
142
161
  - [`CamelCase`](source/camel-case.d.ts) – Convert a string literal to camel-case (`fooBar`).
143
162
  - [`CamelCasedProperties`](source/camel-cased-properties.d.ts) – Convert object properties to camel-case (`fooBar`).
@@ -155,11 +174,6 @@ Click the type names for complete docs.
155
174
  - [`DelimiterCase`](source/delimiter-case.d.ts) – Convert a string literal to a custom string delimiter casing.
156
175
  - [`DelimiterCasedProperties`](source/delimiter-cased-properties.d.ts) – Convert object properties to a custom string delimiter casing.
157
176
  - [`DelimiterCasedPropertiesDeep`](source/delimiter-cased-properties-deep.d.ts) – Convert object properties to a custom string delimiter casing recursively.
158
- - [`Join`](source/join.d.ts) - Join an array of strings and/or numbers using the given string as a delimiter.
159
- - [`Split`](source/split.d.ts) - Represents an array of strings split using a given character or character set.
160
- - [`Trim`](source/trim.d.ts) - Remove leading and trailing spaces from a string.
161
- - [`Get`](source/get.d.ts) - Get a deeply-nested property from an object using a key path, like [Lodash's `.get()`](https://lodash.com/docs/latest#get) function.
162
- - [`LastArrayElement`](source/last-array-element.d.ts) - Extracts the type of the last element of an array.
163
177
 
164
178
  ### Miscellaneous
165
179
 
@@ -20,6 +20,6 @@ async function doSomething(value: Value) {}
20
20
  asyncFunction().then(value => doSomething(value));
21
21
  ```
22
22
 
23
- @category Utilities
23
+ @category Async
24
24
  */
25
25
  export type AsyncReturnType<Target extends AsyncFunction> = PromiseValue<ReturnType<Target>>;
@@ -28,6 +28,6 @@ const getFooAsync: AsyncifiedFooGetter = (someArg) => {
28
28
  }
29
29
  ```
30
30
 
31
- @category Utilities
31
+ @category Async
32
32
  */
33
33
  export type Asyncify<Fn extends (...args: any[]) => any> = SetReturnType<Fn, Promise<PromiseValue<ReturnType<Fn>>>>;
package/source/basic.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
3
3
 
4
- @category Basic
4
+ @category Class
5
5
  */
6
6
  export type Class<T, Arguments extends unknown[] = any[]> = Constructor<T, Arguments> & {prototype: T};
7
7
 
8
8
  /**
9
9
  Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
10
10
 
11
- @category Basic
11
+ @category Class
12
12
  */
13
13
  export type Constructor<T, Arguments extends unknown[] = any[]> = new(...arguments_: Arguments) => T;
14
14
 
@@ -17,21 +17,21 @@ Matches a JSON object.
17
17
 
18
18
  This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
19
19
 
20
- @category Basic
20
+ @category JSON
21
21
  */
22
22
  export type JsonObject = {[Key in string]?: JsonValue};
23
23
 
24
24
  /**
25
25
  Matches a JSON array.
26
26
 
27
- @category Basic
27
+ @category JSON
28
28
  */
29
29
  export type JsonArray = JsonValue[];
30
30
 
31
31
  /**
32
32
  Matches any valid JSON primitive value.
33
33
 
34
- @category Basic
34
+ @category JSON
35
35
  */
36
36
  export type JsonPrimitive = string | number | boolean | null;
37
37
 
@@ -40,6 +40,6 @@ Matches any valid JSON value.
40
40
 
41
41
  @see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
42
42
 
43
- @category Basic
43
+ @category JSON
44
44
  */
45
45
  export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
@@ -67,6 +67,7 @@ const dbResult: CamelCasedProperties<RawOptions> = {
67
67
  };
68
68
  ```
69
69
 
70
- @category Template Literals
70
+ @category Change case
71
+ @category Template literal
71
72
  */
72
73
  export type CamelCase<K> = K extends string ? CamelCaseStringArray<Split<K extends Uppercase<K> ? Lowercase<K> : K, WordSeparators>> : K;
@@ -38,7 +38,9 @@ const result: CamelCasedPropertiesDeep<UserWithFriends> = {
38
38
  };
39
39
  ```
40
40
 
41
- @category Template Literals
41
+ @category Change case
42
+ @category Template literal
43
+ @category Object
42
44
  */
43
45
  export type CamelCasedPropertiesDeep<Value> = Value extends Function
44
46
  ? Value
@@ -21,7 +21,9 @@ const result: CamelCasedProperties<User> = {
21
21
  };
22
22
  ```
23
23
 
24
- @category Template Literals
24
+ @category Change case
25
+ @category Template literal
26
+ @category Object
25
27
  */
26
28
  export type CamelCasedProperties<Value> = Value extends Function
27
29
  ? Value
@@ -37,7 +37,7 @@ type NonStringKeysOnly = ConditionalExcept<Example, string>;
37
37
  //=> {b: string | number; c: () => void; d: {}}
38
38
  ```
39
39
 
40
- @category Utilities
40
+ @category Object
41
41
  */
42
42
  export type ConditionalExcept<Base, Condition> = Except<
43
43
  Base,
@@ -26,7 +26,7 @@ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
26
26
  //=> 'a' | 'c'
27
27
  ```
28
28
 
29
- @category Utilities
29
+ @category Object
30
30
  */
31
31
  export type ConditionalKeys<Base, Condition> = NonNullable<
32
32
  // Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
@@ -36,7 +36,7 @@ type StringKeysOnly = ConditionalPick<Example, string>;
36
36
  //=> {a: string}
37
37
  ```
38
38
 
39
- @category Utilities
39
+ @category Object
40
40
  */
41
41
  export type ConditionalPick<Base, Condition> = Pick<
42
42
  Base,
@@ -3,7 +3,7 @@ import {UpperCaseCharacters, WordSeparators} from '../source/utilities';
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.
5
5
 
6
- @category Template Literals
6
+ @category Template literal
7
7
  */
8
8
  export type SplitIncludingDelimiters<Source extends string, Delimiter extends string> =
9
9
  Source extends '' ? [] :
@@ -79,7 +79,8 @@ const rawCliOptions: OddlyCasedProperties<SomeOptions> = {
79
79
  };
80
80
  ```
81
81
 
82
- @category Template Literals
82
+ @category Change case
83
+ @category Template literal
83
84
  */
84
85
  export type DelimiterCase<Value, Delimiter extends string> = Value extends string
85
86
  ? StringArrayToDelimiterCase<
@@ -38,7 +38,9 @@ const result: DelimiterCasedPropertiesDeep<UserWithFriends, '-'> = {
38
38
  };
39
39
  ```
40
40
 
41
- @category Template Literals
41
+ @category Change case
42
+ @category Template literal
43
+ @category Object
42
44
  */
43
45
  export type DelimiterCasedPropertiesDeep<
44
46
  Value,
@@ -21,7 +21,9 @@ const result: DelimiterCasedProperties<User, '-'> = {
21
21
  };
22
22
  ```
23
23
 
24
- @category Template Literals
24
+ @category Change case
25
+ @category Template literal
26
+ @category Object
25
27
  */
26
28
  export type DelimiterCasedProperties<
27
29
  Value,
@@ -49,7 +49,10 @@ const setExample = new Set(['a', 1]);
49
49
  const setEntries: Entries<typeof setExample> = [['a', 'a'], [1, 1]];
50
50
  ```
51
51
 
52
- @category Utilities
52
+ @category Object
53
+ @category Map
54
+ @category Set
55
+ @category Array
53
56
  */
54
57
  export type Entries<BaseType> =
55
58
  BaseType extends Map<unknown, unknown> ? MapEntries<BaseType>
package/source/entry.d.ts CHANGED
@@ -52,7 +52,10 @@ const setEntryString: Entry<typeof setExample> = ['a', 'a'];
52
52
  const setEntryNumber: Entry<typeof setExample> = [1, 1];
53
53
  ```
54
54
 
55
- @category Utilities
55
+ @category Object
56
+ @category Map
57
+ @category Array
58
+ @category Set
56
59
  */
57
60
  export type Entry<BaseType> =
58
61
  BaseType extends Map<unknown, unknown> ? MapEntry<BaseType>
@@ -50,7 +50,7 @@ type FooWithoutA = Except<Foo, 'a' | 'c'>;
50
50
  //=> {b: string};
51
51
  ```
52
52
 
53
- @category Utilities
53
+ @category Object
54
54
  */
55
55
  export type Except<ObjectType, KeysType extends keyof ObjectType> = {
56
56
  [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
@@ -28,7 +28,7 @@ guestFencingTeam.push('Sam');
28
28
  //=> error TS2339: Property 'push' does not exist on type 'FencingTeam'
29
29
  ```
30
30
 
31
- @category Utilities
31
+ @category Array
32
32
  */
33
33
  export type FixedLengthArray<Element, Length extends number, ArrayPrototype = [Element, ...Element[]]> = Pick<
34
34
  ArrayPrototype,
package/source/get.d.ts CHANGED
@@ -130,6 +130,8 @@ const getName = (apiResponse: ApiResponse) =>
130
130
  //=> Array<{given: string[]; family: string}>
131
131
  ```
132
132
 
133
- @category Template Literals
133
+ @category Template literal
134
+ @category Object
135
+ @category Array
134
136
  */
135
137
  export type Get<BaseType, Path extends string> = GetWithPath<BaseType, ToPath<Path>>;
@@ -12,7 +12,7 @@ import {Includes} from 'type-fest';
12
12
  type hasRed<array extends any[]> = Includes<array, 'red'>;
13
13
  ```
14
14
 
15
- @category Utilities
15
+ @category Array
16
16
  */
17
17
  export type Includes<Value extends readonly any[], Item> =
18
18
  IsEqual<Value[0], Item> extends true
@@ -38,7 +38,7 @@ An example with an array of strings:
38
38
  type MeString = IterableElement<string[]>
39
39
  ```
40
40
 
41
- @category Utilities
41
+ @category Iterable
42
42
  */
43
43
  export type IterableElement<TargetIterable> =
44
44
  TargetIterable extends Iterable<infer ElementType> ?
package/source/join.d.ts CHANGED
@@ -17,7 +17,8 @@ const path: Join<['foo', 'bar', 'baz'], '.'> = ['foo', 'bar', 'baz'].join('.');
17
17
  const path: Join<[1, 2, 3], '.'> = [1, 2, 3].join('.');
18
18
  ```
19
19
 
20
- @category Template Literals
20
+ @category Array
21
+ @category Template literal
21
22
  */
22
23
  export type Join<
23
24
  Strings extends Array<string | number>,
@@ -54,7 +54,7 @@ const timeJson = JSON.parse(JSON.stringify(time)) as Jsonify<typeof time>;
54
54
 
55
55
  @link https://github.com/Microsoft/TypeScript/issues/1897#issuecomment-710744173
56
56
 
57
- @category Utilities
57
+ @category JSON
58
58
  */
59
59
  type Jsonify<T> =
60
60
  // Check if there are any non-JSONable types represented in the union.
@@ -32,6 +32,7 @@ const rawCliOptions: KebabCasedProperties<CliOptions> = {
32
32
  };
33
33
  ```
34
34
 
35
- @category Template Literals
35
+ @category Change case
36
+ @category Template literal
36
37
  */
37
38
  export type KebabCase<Value> = DelimiterCase<Value, '-'>;
@@ -38,6 +38,8 @@ const result: KebabCasedPropertiesDeep<UserWithFriends> = {
38
38
  };
39
39
  ```
40
40
 
41
- @category Template Literals
41
+ @category Change case
42
+ @category Template literal
43
+ @category Object
42
44
  */
43
45
  export type KebabCasedPropertiesDeep<Value> = DelimiterCasedPropertiesDeep<Value, '-'>;
@@ -21,6 +21,8 @@ const result: KebabCasedProperties<User> = {
21
21
  };
22
22
  ```
23
23
 
24
- @category Template Literals
24
+ @category Change case
25
+ @category Template literal
26
+ @category Object
25
27
  */
26
28
  export type KebabCasedProperties<Value> = DelimiterCasedProperties<Value, '-'>;
@@ -15,7 +15,8 @@ typeof lastOf(array);
15
15
  //=> number
16
16
  ```
17
17
 
18
- @category Template Literals
18
+ @category Array
19
+ @category Template literal
19
20
  */
20
21
  export type LastArrayElement<ValueType extends readonly unknown[]> =
21
22
  ValueType extends readonly [infer ElementType]
@@ -27,7 +27,7 @@ const pet: Pet2 = '';
27
27
  // You **will** get auto-completion for `dog` and `cat` literals.
28
28
  ```
29
29
 
30
- @category Utilities
30
+ @category Type
31
31
  */
32
32
  export type LiteralUnion<
33
33
  LiteralType,
@@ -32,7 +32,7 @@ exclusiveOptions = {exclusive1: true, exclusive2: 'hi'};
32
32
  //=> Error
33
33
  ```
34
34
 
35
- @category Utilities
35
+ @category Object
36
36
  */
37
37
  export type MergeExclusive<FirstType, SecondType> =
38
38
  (FirstType | SecondType) extends object ?
package/source/merge.d.ts CHANGED
@@ -22,6 +22,6 @@ type Bar = {
22
22
  const ab: Merge<Foo, Bar> = {a: 1, b: 2};
23
23
  ```
24
24
 
25
- @category Utilities
25
+ @category Object
26
26
  */
27
27
  export type Merge<FirstType, SecondType> = Simplify<Merge_<FirstType, SecondType>>;
@@ -34,7 +34,7 @@ const matrix = emptyMatrix(3);
34
34
  matrix[0][0][0] = 42;
35
35
  ```
36
36
 
37
- @category Utilities
37
+ @category Array
38
38
  */
39
39
  export type MultidimensionalArray<Element, Dimensions extends number> = number extends Dimensions
40
40
  ? Recursive<Element>
@@ -38,7 +38,7 @@ const matrix = emptyMatrix(3);
38
38
  const answer = matrix[0][0][0]; // 42
39
39
  ```
40
40
 
41
- @category Utilities
41
+ @category Array
42
42
  */
43
43
  export type MultidimensionalReadonlyArray<Element, Dimensions extends number> = number extends Dimensions
44
44
  ? Recursive<Element>
@@ -29,7 +29,7 @@ type SomeMutable = Mutable<Foo, 'b' | 'c'>;
29
29
  // }
30
30
  ```
31
31
 
32
- @category Utilities
32
+ @category Object
33
33
  */
34
34
  export type Mutable<BaseType, Keys extends keyof BaseType = keyof BaseType> =
35
35
  Simplify<
@@ -9,7 +9,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
9
9
 
10
10
  @see NegativeInfinity
11
11
 
12
- @category Basic
12
+ @category Numeric
13
13
  */
14
14
  // See https://github.com/microsoft/TypeScript/issues/31752
15
15
  // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
@@ -22,7 +22,7 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277)
22
22
 
23
23
  @see PositiveInfinity
24
24
 
25
- @category Basic
25
+ @category Numeric
26
26
  */
27
27
  // See https://github.com/microsoft/TypeScript/issues/31752
28
28
  // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
@@ -41,7 +41,7 @@ import {Finite} from 'type-fest';
41
41
  declare function setScore<T extends number>(length: Finite<T>): void;
42
42
  ```
43
43
 
44
- @category Utilities
44
+ @category Numeric
45
45
  */
46
46
  export type Finite<T extends number> = T extends PositiveInfinity | NegativeInfinity ? never : T;
47
47
 
@@ -61,12 +61,44 @@ declare function setYear<T extends number>(length: Integer<T>): void;
61
61
  @see NegativeInteger
62
62
  @see NonNegativeInteger
63
63
 
64
- @category Utilities
64
+ @category Numeric
65
65
  */
66
66
  // `${bigint}` is a type that matches a valid bigint literal without the `n` (ex. 1, 0b1, 0o1, 0x1)
67
67
  // Because T is a number and not a string we can effectively use this to filter out any numbers containing decimal points
68
68
  export type Integer<T extends number> = `${T}` extends `${bigint}` ? T : never;
69
69
 
70
+ /**
71
+ A `number` that is not an integer.
72
+ You can't pass a `bigint` as they are already guaranteed to be integers.
73
+
74
+ Use-case: Validating and documenting parameters.
75
+
76
+ @example
77
+ ```
78
+ import {Float} from 'type-fest';
79
+
80
+ declare function setPercentage<T extends number>(length: Float<T>): void;
81
+ ```
82
+
83
+ @see Integer
84
+
85
+ @category Numeric
86
+ */
87
+ export type Float<T extends number> = T extends Integer<T> ? never : T;
88
+
89
+ /**
90
+ A negative (`-∞ < x < 0`) `number` that is not an integer.
91
+ Equivalent to `Negative<Float<T>>`.
92
+
93
+ Use-case: Validating and documenting parameters.
94
+
95
+ @see Negative
96
+ @see Float
97
+
98
+ @category Numeric
99
+ */
100
+ export type NegativeFloat<T extends number> = Negative<Float<T>>;
101
+
70
102
  /**
71
103
  A negative `number`/`bigint` (`-∞ < x < 0`)
72
104
 
@@ -75,7 +107,7 @@ Use-case: Validating and documenting parameters.
75
107
  @see NegativeInteger
76
108
  @see NonNegative
77
109
 
78
- @category Utilities
110
+ @category Numeric
79
111
  */
80
112
  export type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
81
113
 
@@ -90,7 +122,7 @@ Use-case: Validating and documenting parameters.
90
122
  @see Negative
91
123
  @see Integer
92
124
 
93
- @category Utilities
125
+ @category Numeric
94
126
  */
95
127
  export type NegativeInteger<T extends number> = Negative<Integer<T>>;
96
128
 
@@ -109,7 +141,7 @@ import {NonNegative} from 'type-fest';
109
141
  declare function setLength<T extends number>(length: NonNegative<T>): void;
110
142
  ```
111
143
 
112
- @category Utilities
144
+ @category Numeric
113
145
  */
114
146
  export type NonNegative<T extends Numeric> = T extends Zero ? T : Negative<T> extends never ? T : never;
115
147
 
@@ -131,6 +163,6 @@ import {NonNegativeInteger} from 'type-fest';
131
163
  declare function setLength<T extends number>(length: NonNegativeInteger<T>): void;
132
164
  ```
133
165
 
134
- @category Utilities
166
+ @category Numeric
135
167
  */
136
168
  export type NonNegativeInteger<T extends number> = NonNegative<Integer<T>>;
@@ -11,15 +11,29 @@ As well, some guideance on making an `Observable` do not include `closed` proper
11
11
  @see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130
12
12
  @see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85
13
13
  @see https://github.com/benlesh/symbol-observable#making-an-object-observable
14
+
15
+ @category Observable
14
16
  */
15
17
  export type Unsubscribable = {
16
18
  unsubscribe(): void;
17
19
  };
18
20
 
21
+ /**
22
+ @category Observable
23
+ */
19
24
  type OnNext<ValueType> = (value: ValueType) => void;
25
+ /**
26
+ @category Observable
27
+ */
20
28
  type OnError = (error: unknown) => void;
29
+ /**
30
+ @category Observable
31
+ */
21
32
  type OnComplete = () => void;
22
33
 
34
+ /**
35
+ @category Observable
36
+ */
23
37
  export type Observer<ValueType> = {
24
38
  next: OnNext<ValueType>;
25
39
  error: OnError;
@@ -40,7 +54,7 @@ But `Observable` implementations have evolved to preferring case 2 and some impl
40
54
  @see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L246-L259
41
55
  @see https://benlesh.com/posts/learning-observable-by-building-observable/
42
56
 
43
- @category Basic
57
+ @category Observable
44
58
  */
45
59
  export interface ObservableLike<ValueType = unknown> {
46
60
  subscribe(observer?: Partial<Observer<ValueType>>): Unsubscribable;
@@ -69,6 +69,6 @@ type Person = {
69
69
  };
70
70
  ```
71
71
 
72
- @category Utilities
72
+ @category Type
73
73
  */
74
74
  export type Opaque<Type, Token = unknown> = Type & Tagged<Token>;
@@ -635,7 +635,7 @@ declare namespace PackageJson {
635
635
  /**
636
636
  Type for [npm's `package.json` file](https://docs.npmjs.com/creating-a-package-json-file). Also includes types for fields used by other popular projects, like TypeScript and Yarn.
637
637
 
638
- @category Miscellaneous
638
+ @category File
639
639
  */
640
640
  export type PackageJson =
641
641
  PackageJson.PackageJsonStandard &
@@ -28,7 +28,10 @@ const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
28
28
  settings = applySavedSettings({textEditor: {fontWeight: 500}});
29
29
  ```
30
30
 
31
- @category Utilities
31
+ @category Object
32
+ @category Array
33
+ @category Set
34
+ @category Map
32
35
  */
33
36
  export type PartialDeep<T> = T extends Primitive
34
37
  ? Partial<T>
@@ -30,7 +30,8 @@ const dbResult: CamelCasedProperties<ModelProps> = {
30
30
  };
31
31
  ```
32
32
 
33
- @category Template Literals
33
+ @category Change case
34
+ @category Template literal
34
35
  */
35
36
  export type PascalCase<Value> = CamelCase<Value> extends string
36
37
  ? Capitalize<CamelCase<Value>>
@@ -38,7 +38,9 @@ const result: PascalCasedPropertiesDeep<UserWithFriends> = {
38
38
  };
39
39
  ```
40
40
 
41
- @category Template Literals
41
+ @category Change case
42
+ @category Template literal
43
+ @category Object
42
44
  */
43
45
  export type PascalCasedPropertiesDeep<Value> = Value extends Function
44
46
  ? Value
@@ -21,7 +21,9 @@ const result: PascalCasedProperties<User> = {
21
21
  };
22
22
  ```
23
23
 
24
- @category Template Literals
24
+ @category Change case
25
+ @category Template literal
26
+ @category Object
25
27
  */
26
28
  export type PascalCasedProperties<Value> = Value extends Function
27
29
  ? Value
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
3
3
 
4
- @category Basic
4
+ @category Type
5
5
  */
6
6
  export type Primitive =
7
7
  | null
@@ -18,8 +18,8 @@ async function logger(getLogEntry: () => Promisable<string>): Promise<void> {
18
18
 
19
19
  logger(() => 'foo');
20
20
  logger(() => Promise.resolve('bar'));
21
-
22
- @category Utilities
23
21
  ```
22
+
23
+ @category Async
24
24
  */
25
25
  export type Promisable<T> = T | PromiseLike<T>;
@@ -24,6 +24,6 @@ type RecursiveAsyncData = Promise<Promise<string> >;
24
24
  let recursiveAsyncData: PromiseValue<RecursiveAsyncData> = Promise.resolve(Promise.resolve('ABC'));
25
25
  ```
26
26
 
27
- @category Utilities
27
+ @category Async
28
28
  */
29
29
  export type PromiseValue<PromiseType> = PromiseType extends PromiseLike<infer Value> ? PromiseValue<Value> : PromiseType;
@@ -29,7 +29,10 @@ data.foo.push('bar');
29
29
  //=> error TS2339: Property 'push' does not exist on type 'readonly string[]'
30
30
  ```
31
31
 
32
- @category Utilities
32
+ @category Object
33
+ @category Array
34
+ @category Set
35
+ @category Map
33
36
  */
34
37
  export type ReadonlyDeep<T> = T extends Primitive | ((...arguments: any[]) => unknown)
35
38
  ? T
@@ -27,7 +27,7 @@ const responder2: RequireAllOrNone<Responder, 'text' | 'json'> = {
27
27
  };
28
28
  ```
29
29
 
30
- @category Utilities
30
+ @category Object
31
31
  */
32
32
  export type RequireAllOrNone<ObjectType, KeysType extends keyof ObjectType = never> = (
33
33
  | Required<Pick<ObjectType, KeysType>> // Require all of the given keys.
@@ -20,7 +20,7 @@ const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
20
20
  };
21
21
  ```
22
22
 
23
- @category Utilities
23
+ @category Object
24
24
  */
25
25
  export type RequireAtLeastOne<
26
26
  ObjectType,
@@ -25,7 +25,7 @@ const responder: RequireExactlyOne<Responder, 'text' | 'json'> = {
25
25
  };
26
26
  ```
27
27
 
28
- @category Utilities
28
+ @category Object
29
29
  */
30
30
  export type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> =
31
31
  {[Key in KeysType]: (
@@ -23,7 +23,8 @@ import {ScreamingSnakeCase} from 'type-fest';
23
23
  const someVariable: ScreamingSnakeCase<'fooBar'> = 'FOO_BAR';
24
24
  ```
25
25
 
26
- @category Template Literals
26
+ @category Change case
27
+ @category Template literal
27
28
  */
28
29
  export type ScreamingSnakeCase<Value> = Value extends string
29
30
  ? IsScreamingSnakeCase<Value> extends true
@@ -24,7 +24,7 @@ type SomeOptional = SetOptional<Foo, 'b' | 'c'>;
24
24
  // }
25
25
  ```
26
26
 
27
- @category Utilities
27
+ @category Object
28
28
  */
29
29
  export type SetOptional<BaseType, Keys extends keyof BaseType> =
30
30
  Simplify<
@@ -24,7 +24,7 @@ type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
24
24
  // }
25
25
  ```
26
26
 
27
- @category Utilities
27
+ @category Object
28
28
  */
29
29
  export type SetRequired<BaseType, Keys extends keyof BaseType> =
30
30
  Simplify<
@@ -17,7 +17,7 @@ type MyWrappedFunction = SetReturnType<MyFunctionThatCanThrow, SomeOtherType | u
17
17
  //=> type MyWrappedFunction = (foo: SomeType, bar: unknown) => SomeOtherType | undefined;
18
18
  ```
19
19
 
20
- @category Utilities
20
+ @category Function
21
21
  */
22
22
  export type SetReturnType<Fn extends (...args: any[]) => any, TypeToReturn> =
23
23
  // Just using `Parameters<Fn>` isn't ideal because it doesn't handle the `this` fake parameter.
@@ -53,6 +53,6 @@ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface`
53
53
 
54
54
  @link https://github.com/microsoft/TypeScript/issues/15300
55
55
 
56
- @category Utilities
56
+ @category Object
57
57
  */
58
58
  export type Simplify<T> = {[KeyType in keyof T]: T[KeyType]};
@@ -32,6 +32,7 @@ const dbResult: SnakeCasedProperties<ModelProps> = {
32
32
  };
33
33
  ```
34
34
 
35
- @category Template Literals
35
+ @category Change case
36
+ @category Template literal
36
37
  */
37
38
  export type SnakeCase<Value> = DelimiterCase<Value, '_'>;
@@ -38,6 +38,8 @@ const result: SnakeCasedPropertiesDeep<UserWithFriends> = {
38
38
  };
39
39
  ```
40
40
 
41
- @category Template Literals
41
+ @category Change case
42
+ @category Template literal
43
+ @category Object
42
44
  */
43
45
  export type SnakeCasedPropertiesDeep<Value> = DelimiterCasedPropertiesDeep<Value, '_'>;
@@ -21,6 +21,8 @@ const result: SnakeCasedProperties<User> = {
21
21
  };
22
22
  ```
23
23
 
24
- @category Template Literals
24
+ @category Change case
25
+ @category Template literal
26
+ @category Object
25
27
  */
26
28
  export type SnakeCasedProperties<Value> = DelimiterCasedProperties<Value, '_'>;
package/source/split.d.ts CHANGED
@@ -16,7 +16,8 @@ let array: Item[];
16
16
  array = split(items, ',');
17
17
  ```
18
18
 
19
- @category Template Literals
19
+ @category String
20
+ @category Template literal
20
21
  */
21
22
  export type Split<
22
23
  S extends string,
@@ -18,6 +18,6 @@ const carForm: Stringified<Car> = {
18
18
  };
19
19
  ```
20
20
 
21
- @category Utilities
21
+ @category Object
22
22
  */
23
23
  export type Stringified<ObjectType> = {[KeyType in keyof ObjectType]: string};
package/source/trim.d.ts CHANGED
@@ -19,6 +19,7 @@ Trim<' foo '>
19
19
  //=> 'foo'
20
20
  ```
21
21
 
22
- @category Template Literals
22
+ @category String
23
+ @category Template literal
23
24
  */
24
25
  export type Trim<V extends string> = TrimLeft<TrimRight<V>>;
@@ -1040,7 +1040,7 @@ declare namespace TsConfigJson {
1040
1040
  /**
1041
1041
  Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (TypeScript 3.7).
1042
1042
 
1043
- @category Miscellaneous
1043
+ @category File
1044
1044
  */
1045
1045
  export interface TsConfigJson {
1046
1046
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
3
3
 
4
- @category Basic
4
+ @category Array
5
5
  */
6
6
  export type TypedArray =
7
7
  | Int8Array
@@ -41,7 +41,7 @@ type Intersection = UnionToIntersection<Union>;
41
41
  //=> {a1(): void; b1(): void; a2(argA: string): void; b2(argB: string): void}
42
42
  ```
43
43
 
44
- @category Utilities
44
+ @category Type
45
45
  */
46
46
  export type UnionToIntersection<Union> = (
47
47
  // `extends unknown` is always going to be the case and is used to convert the
@@ -37,6 +37,6 @@ onlyBar('bar');
37
37
  //=> 2
38
38
  ```
39
39
 
40
- @category Utilities
40
+ @category Object
41
41
  */
42
42
  export type ValueOf<ObjectType, ValueType extends keyof ObjectType = keyof ObjectType> = ObjectType[ValueType];