type-fest 2.5.2 → 2.7.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
@@ -37,6 +37,16 @@ export {SetReturnType} from './source/set-return-type';
37
37
  export {Asyncify} from './source/asyncify';
38
38
  export {Simplify} from './source/simplify';
39
39
  export {Jsonify} from './source/jsonify';
40
+ export {
41
+ PositiveInfinity,
42
+ NegativeInfinity,
43
+ Finite,
44
+ Integer,
45
+ Negative,
46
+ NonNegative,
47
+ NegativeInteger,
48
+ NonNegativeInteger,
49
+ } from './source/numeric';
40
50
 
41
51
  // Template literal types
42
52
  export {CamelCase} from './source/camel-case';
package/license CHANGED
@@ -1,9 +1 @@
1
- MIT License
2
-
3
- Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
-
7
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
-
9
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ SPDX-License-Identifier: (MIT OR CC0-1.0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "2.5.2",
3
+ "version": "2.7.0",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
@@ -35,7 +35,7 @@
35
35
  "@sindresorhus/tsconfig": "~0.7.0",
36
36
  "expect-type": "^0.12.0",
37
37
  "tsd": "^0.17.0",
38
- "typescript": "^4.1.3",
38
+ "typescript": ">=4.2",
39
39
  "xo": "^0.43.0"
40
40
  },
41
41
  "types": "./index.d.ts",
package/readme.md CHANGED
@@ -58,8 +58,8 @@ PR welcome for additional commonly needed types and docs improvements. Read the
58
58
 
59
59
  ## Install
60
60
 
61
- ```
62
- $ npm install type-fest
61
+ ```sh
62
+ npm install type-fest
63
63
  ```
64
64
 
65
65
  *Requires TypeScript >=4.2*
@@ -111,7 +111,6 @@ Click the type names for complete docs.
111
111
  - [`SetOptional`](source/set-optional.d.ts) - Create a type that makes the given keys optional.
112
112
  - [`SetRequired`](source/set-required.d.ts) - Create a type that makes the given keys required.
113
113
  - [`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
- - [`PromiseValue`](source/promise-value.d.ts) - Returns the type that is wrapped inside a `Promise`.
115
114
  - [`AsyncReturnType`](source/async-return-type.d.ts) - Unwrap the return type of a function that returns a `Promise`.
116
115
  - [`ConditionalKeys`](source/conditional-keys.d.ts) - Extract keys from a shape where values extend the given `Condition` type.
117
116
  - [`ConditionalPick`](source/conditional-pick.d.ts) - Like `Pick` except it selects properties from a shape where the values extend the given `Condition` type.
@@ -129,6 +128,14 @@ Click the type names for complete docs.
129
128
  - [`Includes`](source/includes.d.ts) - Returns a boolean for whether the given array includes the given item.
130
129
  - [`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.
131
130
  - [`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.
132
139
 
133
140
  ### Template literal types
134
141
 
@@ -167,6 +174,13 @@ Click the type names for complete docs.
167
174
  - [`Dictionary`](https://github.com/sindresorhus/type-fest/issues/33) - You only save a few characters (`Dictionary<number>` vs `Record<string, number>`) from [`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type), which is more flexible and well-known. Also, you shouldn't use an object as a dictionary. We have `Map` in JavaScript now.
168
175
  - [`ExtractProperties` and `ExtractMethods`](https://github.com/sindresorhus/type-fest/pull/4) - The types violate the single responsibility principle. Instead, refine your types into more granular type hierarchies.
169
176
  - [`Url2Json`](https://github.com/sindresorhus/type-fest/pull/262) - Inferring search parameters from a URL string is a cute idea, but not very useful in practice, since search parameters are usually dynamic and defined separately.
177
+ - [`Nullish`](https://github.com/sindresorhus/type-fest/pull/318) - The type only saves a couple of characters, not everyone knows what “nullish” means, and I'm also trying to [get away from `null`](https://github.com/sindresorhus/meta/discussions/7).
178
+
179
+ ## Alternative type names
180
+
181
+ *If you know one of our types by a different name, add it here for discovery.*
182
+
183
+ - `PartialBy` - See [`SetOptional`](https://github.com/sindresorhus/type-fest/blob/main/source/set-optional.d.ts)
170
184
 
171
185
  ## Tips
172
186
 
@@ -787,7 +801,7 @@ You can find some examples in the [TypeScript docs](https://www.typescriptlang.o
787
801
 
788
802
  ## License
789
803
 
790
- (MIT OR CC0-1.0)
804
+ SPDX-License-Identifier: (MIT OR CC0-1.0)
791
805
 
792
806
  ---
793
807
 
@@ -40,6 +40,8 @@ It receives `UsedWordSeparators` and `UsedUpperCaseCharacters` as input to ensur
40
40
  type StringArrayToDelimiterCase<Parts extends readonly any[], Start extends boolean, UsedWordSeparators extends string, UsedUpperCaseCharacters extends string, Delimiter extends string> =
41
41
  Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
42
42
  ? `${StringPartToDelimiterCase<FirstPart, Start, UsedWordSeparators, UsedUpperCaseCharacters, Delimiter>}${StringArrayToDelimiterCase<RemainingParts, false, UsedWordSeparators, UsedUpperCaseCharacters, Delimiter>}`
43
+ : Parts extends [string]
44
+ ? string
43
45
  : '';
44
46
 
45
47
  /**
package/source/join.d.ts CHANGED
@@ -26,4 +26,4 @@ export type Join<
26
26
  Strings extends [string | number] ? `${Strings[0]}` :
27
27
  // @ts-expect-error `Rest` is inferred as `unknown` here: https://github.com/microsoft/TypeScript/issues/45281
28
28
  Strings extends [string | number, ...infer Rest] ? `${Strings[0]}${Delimiter}${Join<Rest, Delimiter>}` :
29
- string | number;
29
+ string;
@@ -0,0 +1,136 @@
1
+ type Numeric = number | bigint;
2
+
3
+ type Zero = 0 | 0n;
4
+
5
+ /**
6
+ Matches the hidden `Infinity` type.
7
+
8
+ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
9
+
10
+ @see NegativeInfinity
11
+
12
+ @category Basic
13
+ */
14
+ // See https://github.com/microsoft/TypeScript/issues/31752
15
+ // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
16
+ export type PositiveInfinity = 1e999;
17
+
18
+ /**
19
+ Matches the hidden `-Infinity` type.
20
+
21
+ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/32277) if you want to have this type as a built-in in TypeScript.
22
+
23
+ @see PositiveInfinity
24
+
25
+ @category Basic
26
+ */
27
+ // See https://github.com/microsoft/TypeScript/issues/31752
28
+ // eslint-disable-next-line @typescript-eslint/no-loss-of-precision
29
+ export type NegativeInfinity = -1e999;
30
+
31
+ /**
32
+ A finite `number`.
33
+ You can't pass a `bigint` as they are already guaranteed to be finite.
34
+
35
+ Use-case: Validating and documenting parameters.
36
+
37
+ @example
38
+ ```
39
+ import {Finite} from 'type-fest';
40
+
41
+ declare function setScore<T extends number>(length: Finite<T>): void;
42
+ ```
43
+
44
+ @category Utilities
45
+ */
46
+ export type Finite<T extends number> = T extends PositiveInfinity | NegativeInfinity ? never : T;
47
+
48
+ /**
49
+ A `number` that is an integer.
50
+ You can't pass a `bigint` as they are already guaranteed to be integers.
51
+
52
+ Use-case: Validating and documenting parameters.
53
+
54
+ @example
55
+ ```
56
+ import {Integer} from 'type-fest';
57
+
58
+ declare function setYear<T extends number>(length: Integer<T>): void;
59
+ ```
60
+
61
+ @see NegativeInteger
62
+ @see NonNegativeInteger
63
+
64
+ @category Utilities
65
+ */
66
+ // `${bigint}` is a type that matches a valid bigint literal without the `n` (ex. 1, 0b1, 0o1, 0x1)
67
+ // Because T is a number and not a string we can effectively use this to filter out any numbers containing decimal points
68
+ export type Integer<T extends number> = `${T}` extends `${bigint}` ? T : never;
69
+
70
+ /**
71
+ A negative `number`/`bigint` (`-∞ < x < 0`)
72
+
73
+ Use-case: Validating and documenting parameters.
74
+
75
+ @see NegativeInteger
76
+ @see NonNegative
77
+
78
+ @category Utilities
79
+ */
80
+ export type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
81
+
82
+ /**
83
+ A negative (`-∞ < x < 0`) `number` that is an integer.
84
+ Equivalent to `Negative<Integer<T>>`.
85
+
86
+ You can't pass a `bigint` as they are already guaranteed to be integers, instead use `Negative<T>`.
87
+
88
+ Use-case: Validating and documenting parameters.
89
+
90
+ @see Negative
91
+ @see Integer
92
+
93
+ @category Utilities
94
+ */
95
+ export type NegativeInteger<T extends number> = Negative<Integer<T>>;
96
+
97
+ /**
98
+ A non-negative `number`/`bigint` (`0 <= x < ∞`).
99
+
100
+ Use-case: Validating and documenting parameters.
101
+
102
+ @see NonNegativeInteger
103
+ @see Negative
104
+
105
+ @example
106
+ ```
107
+ import {NonNegative} from 'type-fest';
108
+
109
+ declare function setLength<T extends number>(length: NonNegative<T>): void;
110
+ ```
111
+
112
+ @category Utilities
113
+ */
114
+ export type NonNegative<T extends Numeric> = T extends Zero ? T : Negative<T> extends never ? T : never;
115
+
116
+ /**
117
+ A non-negative (`0 <= x < ∞`) `number` that is an integer.
118
+ Equivalent to `NonNegative<Integer<T>>`.
119
+
120
+ You can't pass a `bigint` as they are already guaranteed to be integers, instead use `NonNegative<T>`.
121
+
122
+ Use-case: Validating and documenting parameters.
123
+
124
+ @see NonNegative
125
+ @see Integer
126
+
127
+ @example
128
+ ```
129
+ import {NonNegativeInteger} from 'type-fest';
130
+
131
+ declare function setLength<T extends number>(length: NonNegativeInteger<T>): void;
132
+ ```
133
+
134
+ @category Utilities
135
+ */
136
+ export type NonNegativeInteger<T extends number> = NonNegative<Integer<T>>;
@@ -1,4 +1,6 @@
1
1
  /**
2
+ @deprecated Use the built-in [`Awaited` type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html#the-awaited-type-and-promise-improvements) instead.
3
+
2
4
  Returns the type that is wrapped inside a `Promise` type.
3
5
  If the type is a nested Promise, it is unwrapped recursively until a non-Promise type is obtained.
4
6
  If the type is not a `Promise`, the type itself is returned.
@@ -15,6 +15,7 @@ declare namespace TsConfigJson {
15
15
  | 'ES6'
16
16
  | 'ES2015'
17
17
  | 'ES2020'
18
+ | 'ES2022'
18
19
  | 'ESNext'
19
20
  | 'None'
20
21
  // Lowercase alternatives
@@ -25,6 +26,7 @@ declare namespace TsConfigJson {
25
26
  | 'es6'
26
27
  | 'es2015'
27
28
  | 'es2020'
29
+ | 'es2022'
28
30
  | 'esnext'
29
31
  | 'none';
30
32