type-fest 2.5.3 → 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.
- package/index.d.ts +12 -0
- package/license +1 -9
- package/package.json +1 -1
- package/readme.md +37 -15
- package/source/async-return-type.d.ts +1 -1
- package/source/asyncify.d.ts +1 -1
- package/source/basic.d.ts +6 -6
- package/source/camel-case.d.ts +2 -1
- package/source/camel-cased-properties-deep.d.ts +3 -1
- package/source/camel-cased-properties.d.ts +3 -1
- package/source/conditional-except.d.ts +1 -1
- package/source/conditional-keys.d.ts +1 -1
- package/source/conditional-pick.d.ts +1 -1
- package/source/delimiter-case.d.ts +5 -2
- package/source/delimiter-cased-properties-deep.d.ts +3 -1
- package/source/delimiter-cased-properties.d.ts +3 -1
- package/source/entries.d.ts +4 -1
- package/source/entry.d.ts +4 -1
- package/source/except.d.ts +1 -1
- package/source/fixed-length-array.d.ts +1 -1
- package/source/get.d.ts +3 -1
- package/source/includes.d.ts +1 -1
- package/source/iterable-element.d.ts +1 -1
- package/source/join.d.ts +2 -1
- package/source/jsonify.d.ts +1 -1
- package/source/kebab-case.d.ts +2 -1
- package/source/kebab-cased-properties-deep.d.ts +3 -1
- package/source/kebab-cased-properties.d.ts +3 -1
- package/source/last-array-element.d.ts +2 -1
- package/source/literal-union.d.ts +1 -1
- package/source/merge-exclusive.d.ts +1 -1
- package/source/merge.d.ts +1 -1
- package/source/multidimensional-array.d.ts +1 -1
- package/source/multidimensional-readonly-array.d.ts +1 -1
- package/source/mutable.d.ts +1 -1
- package/source/numeric.d.ts +168 -0
- package/source/observable-like.d.ts +15 -1
- package/source/opaque.d.ts +1 -1
- package/source/package-json.d.ts +1 -1
- package/source/partial-deep.d.ts +4 -1
- package/source/pascal-case.d.ts +2 -1
- package/source/pascal-cased-properties-deep.d.ts +3 -1
- package/source/pascal-cased-properties.d.ts +3 -1
- package/source/primitive.d.ts +1 -1
- package/source/promisable.d.ts +2 -2
- package/source/promise-value.d.ts +3 -1
- package/source/readonly-deep.d.ts +4 -1
- package/source/require-all-or-none.d.ts +1 -1
- package/source/require-at-least-one.d.ts +1 -1
- package/source/require-exactly-one.d.ts +1 -1
- package/source/screaming-snake-case.d.ts +2 -1
- package/source/set-optional.d.ts +1 -1
- package/source/set-required.d.ts +1 -1
- package/source/set-return-type.d.ts +1 -1
- package/source/simplify.d.ts +1 -1
- package/source/snake-case.d.ts +2 -1
- package/source/snake-cased-properties-deep.d.ts +3 -1
- package/source/snake-cased-properties.d.ts +3 -1
- package/source/split.d.ts +2 -1
- package/source/stringified.d.ts +1 -1
- package/source/trim.d.ts +2 -1
- package/source/tsconfig-json.d.ts +3 -1
- package/source/typed-array.d.ts +1 -1
- package/source/union-to-intersection.d.ts +1 -1
- package/source/value-of.d.ts +1 -1
package/index.d.ts
CHANGED
|
@@ -37,6 +37,18 @@ 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
|
+
Float,
|
|
46
|
+
NegativeFloat,
|
|
47
|
+
Negative,
|
|
48
|
+
NonNegative,
|
|
49
|
+
NegativeInteger,
|
|
50
|
+
NonNegativeInteger,
|
|
51
|
+
} from './source/numeric';
|
|
40
52
|
|
|
41
53
|
// Template literal types
|
|
42
54
|
export {CamelCase} from './source/camel-case';
|
package/license
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
MIT
|
|
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
package/readme.md
CHANGED
|
@@ -106,31 +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
|
-
- [`PromiseValue`](source/promise-value.d.ts) - Returns the type that is wrapped inside a `Promise`.
|
|
115
|
-
- [`AsyncReturnType`](source/async-return-type.d.ts) - Unwrap the return type of a function that returns a `Promise`.
|
|
116
113
|
- [`ConditionalKeys`](source/conditional-keys.d.ts) - Extract keys from a shape where values extend the given `Condition` type.
|
|
117
114
|
- [`ConditionalPick`](source/conditional-pick.d.ts) - Like `Pick` except it selects properties from a shape where the values extend the given `Condition` type.
|
|
118
115
|
- [`ConditionalExcept`](source/conditional-except.d.ts) - Like `Omit` except it removes properties from a shape where the values extend the given `Condition` type.
|
|
119
116
|
- [`UnionToIntersection`](source/union-to-intersection.d.ts) - Convert a union type to an intersection type.
|
|
120
117
|
- [`Stringified`](source/stringified.d.ts) - Create a type with the keys of the given type changed to `string` type.
|
|
121
|
-
- [`FixedLengthArray`](source/fixed-length-array.d.ts) - Create a type that represents an array of the given type and length.
|
|
122
|
-
- [`MultidimensionalArray`](source/multidimensional-array.d.ts) - Create a type that represents a multidimensional array of the given type and dimensions.
|
|
123
|
-
- [`MultidimensionalReadonlyArray`](source/multidimensional-readonly-array.d.ts) - Create a type that represents a multidimensional readonly array of the given type and dimensions.
|
|
124
118
|
- [`IterableElement`](source/iterable-element.d.ts) - Get the element type of an `Iterable`/`AsyncIterable`. For example, an array or a generator.
|
|
125
119
|
- [`Entry`](source/entry.d.ts) - Create a type that represents the type of an entry of a collection.
|
|
126
120
|
- [`Entries`](source/entries.d.ts) - Create a type that represents the type of the entries of a collection.
|
|
127
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.
|
|
128
|
-
- [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type.
|
|
129
|
-
- [`Includes`](source/includes.d.ts) - Returns a boolean for whether the given array includes the given item.
|
|
130
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.
|
|
131
123
|
- [`Jsonify`](source/jsonify.d.ts) - Transform a type to one that is assignable to the `JsonValue` type.
|
|
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
|
|
132
147
|
|
|
133
|
-
|
|
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
|
|
134
160
|
|
|
135
161
|
- [`CamelCase`](source/camel-case.d.ts) – Convert a string literal to camel-case (`fooBar`).
|
|
136
162
|
- [`CamelCasedProperties`](source/camel-cased-properties.d.ts) – Convert object properties to camel-case (`fooBar`).
|
|
@@ -148,11 +174,6 @@ Click the type names for complete docs.
|
|
|
148
174
|
- [`DelimiterCase`](source/delimiter-case.d.ts) – Convert a string literal to a custom string delimiter casing.
|
|
149
175
|
- [`DelimiterCasedProperties`](source/delimiter-cased-properties.d.ts) – Convert object properties to a custom string delimiter casing.
|
|
150
176
|
- [`DelimiterCasedPropertiesDeep`](source/delimiter-cased-properties-deep.d.ts) – Convert object properties to a custom string delimiter casing recursively.
|
|
151
|
-
- [`Join`](source/join.d.ts) - Join an array of strings and/or numbers using the given string as a delimiter.
|
|
152
|
-
- [`Split`](source/split.d.ts) - Represents an array of strings split using a given character or character set.
|
|
153
|
-
- [`Trim`](source/trim.d.ts) - Remove leading and trailing spaces from a string.
|
|
154
|
-
- [`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.
|
|
155
|
-
- [`LastArrayElement`](source/last-array-element.d.ts) - Extracts the type of the last element of an array.
|
|
156
177
|
|
|
157
178
|
### Miscellaneous
|
|
158
179
|
|
|
@@ -167,6 +188,7 @@ Click the type names for complete docs.
|
|
|
167
188
|
- [`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
189
|
- [`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
190
|
- [`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.
|
|
191
|
+
- [`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).
|
|
170
192
|
|
|
171
193
|
## Alternative type names
|
|
172
194
|
|
|
@@ -793,7 +815,7 @@ You can find some examples in the [TypeScript docs](https://www.typescriptlang.o
|
|
|
793
815
|
|
|
794
816
|
## License
|
|
795
817
|
|
|
796
|
-
(MIT OR CC0-1.0)
|
|
818
|
+
SPDX-License-Identifier: (MIT OR CC0-1.0)
|
|
797
819
|
|
|
798
820
|
---
|
|
799
821
|
|
package/source/asyncify.d.ts
CHANGED
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
43
|
+
@category JSON
|
|
44
44
|
*/
|
|
45
45
|
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
package/source/camel-case.d.ts
CHANGED
|
@@ -67,6 +67,7 @@ const dbResult: CamelCasedProperties<RawOptions> = {
|
|
|
67
67
|
};
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
@category
|
|
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
|
|
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
|
|
@@ -26,7 +26,7 @@ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
|
|
|
26
26
|
//=> 'a' | 'c'
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
-
@category
|
|
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.
|
|
@@ -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
|
|
6
|
+
@category Template literal
|
|
7
7
|
*/
|
|
8
8
|
export type SplitIncludingDelimiters<Source extends string, Delimiter extends string> =
|
|
9
9
|
Source extends '' ? [] :
|
|
@@ -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
|
/**
|
|
@@ -77,7 +79,8 @@ const rawCliOptions: OddlyCasedProperties<SomeOptions> = {
|
|
|
77
79
|
};
|
|
78
80
|
```
|
|
79
81
|
|
|
80
|
-
@category
|
|
82
|
+
@category Change case
|
|
83
|
+
@category Template literal
|
|
81
84
|
*/
|
|
82
85
|
export type DelimiterCase<Value, Delimiter extends string> = Value extends string
|
|
83
86
|
? StringArrayToDelimiterCase<
|
package/source/entries.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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>
|
package/source/except.d.ts
CHANGED
|
@@ -50,7 +50,7 @@ type FooWithoutA = Except<Foo, 'a' | 'c'>;
|
|
|
50
50
|
//=> {b: string};
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
@category
|
|
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
|
|
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
|
|
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>>;
|
package/source/includes.d.ts
CHANGED
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
|
|
20
|
+
@category Array
|
|
21
|
+
@category Template literal
|
|
21
22
|
*/
|
|
22
23
|
export type Join<
|
|
23
24
|
Strings extends Array<string | number>,
|
package/source/jsonify.d.ts
CHANGED
|
@@ -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
|
|
57
|
+
@category JSON
|
|
58
58
|
*/
|
|
59
59
|
type Jsonify<T> =
|
|
60
60
|
// Check if there are any non-JSONable types represented in the union.
|
package/source/kebab-case.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ const result: KebabCasedPropertiesDeep<UserWithFriends> = {
|
|
|
38
38
|
};
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
@category
|
|
41
|
+
@category Change case
|
|
42
|
+
@category Template literal
|
|
43
|
+
@category Object
|
|
42
44
|
*/
|
|
43
45
|
export type KebabCasedPropertiesDeep<Value> = DelimiterCasedPropertiesDeep<Value, '-'>;
|
package/source/merge.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ const matrix = emptyMatrix(3);
|
|
|
38
38
|
const answer = matrix[0][0][0]; // 42
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
@category
|
|
41
|
+
@category Array
|
|
42
42
|
*/
|
|
43
43
|
export type MultidimensionalReadonlyArray<Element, Dimensions extends number> = number extends Dimensions
|
|
44
44
|
? Recursive<Element>
|
package/source/mutable.d.ts
CHANGED
|
@@ -0,0 +1,168 @@
|
|
|
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 Numeric
|
|
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 Numeric
|
|
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 Numeric
|
|
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 Numeric
|
|
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 `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
|
+
|
|
102
|
+
/**
|
|
103
|
+
A negative `number`/`bigint` (`-∞ < x < 0`)
|
|
104
|
+
|
|
105
|
+
Use-case: Validating and documenting parameters.
|
|
106
|
+
|
|
107
|
+
@see NegativeInteger
|
|
108
|
+
@see NonNegative
|
|
109
|
+
|
|
110
|
+
@category Numeric
|
|
111
|
+
*/
|
|
112
|
+
export type Negative<T extends Numeric> = T extends Zero ? never : `${T}` extends `-${string}` ? T : never;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
A negative (`-∞ < x < 0`) `number` that is an integer.
|
|
116
|
+
Equivalent to `Negative<Integer<T>>`.
|
|
117
|
+
|
|
118
|
+
You can't pass a `bigint` as they are already guaranteed to be integers, instead use `Negative<T>`.
|
|
119
|
+
|
|
120
|
+
Use-case: Validating and documenting parameters.
|
|
121
|
+
|
|
122
|
+
@see Negative
|
|
123
|
+
@see Integer
|
|
124
|
+
|
|
125
|
+
@category Numeric
|
|
126
|
+
*/
|
|
127
|
+
export type NegativeInteger<T extends number> = Negative<Integer<T>>;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
A non-negative `number`/`bigint` (`0 <= x < ∞`).
|
|
131
|
+
|
|
132
|
+
Use-case: Validating and documenting parameters.
|
|
133
|
+
|
|
134
|
+
@see NonNegativeInteger
|
|
135
|
+
@see Negative
|
|
136
|
+
|
|
137
|
+
@example
|
|
138
|
+
```
|
|
139
|
+
import {NonNegative} from 'type-fest';
|
|
140
|
+
|
|
141
|
+
declare function setLength<T extends number>(length: NonNegative<T>): void;
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
@category Numeric
|
|
145
|
+
*/
|
|
146
|
+
export type NonNegative<T extends Numeric> = T extends Zero ? T : Negative<T> extends never ? T : never;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
A non-negative (`0 <= x < ∞`) `number` that is an integer.
|
|
150
|
+
Equivalent to `NonNegative<Integer<T>>`.
|
|
151
|
+
|
|
152
|
+
You can't pass a `bigint` as they are already guaranteed to be integers, instead use `NonNegative<T>`.
|
|
153
|
+
|
|
154
|
+
Use-case: Validating and documenting parameters.
|
|
155
|
+
|
|
156
|
+
@see NonNegative
|
|
157
|
+
@see Integer
|
|
158
|
+
|
|
159
|
+
@example
|
|
160
|
+
```
|
|
161
|
+
import {NonNegativeInteger} from 'type-fest';
|
|
162
|
+
|
|
163
|
+
declare function setLength<T extends number>(length: NonNegativeInteger<T>): void;
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
@category Numeric
|
|
167
|
+
*/
|
|
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
|
|
57
|
+
@category Observable
|
|
44
58
|
*/
|
|
45
59
|
export interface ObservableLike<ValueType = unknown> {
|
|
46
60
|
subscribe(observer?: Partial<Observer<ValueType>>): Unsubscribable;
|
package/source/opaque.d.ts
CHANGED
package/source/package-json.d.ts
CHANGED
|
@@ -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
|
|
638
|
+
@category File
|
|
639
639
|
*/
|
|
640
640
|
export type PackageJson =
|
|
641
641
|
PackageJson.PackageJsonStandard &
|
package/source/partial-deep.d.ts
CHANGED
|
@@ -28,7 +28,10 @@ const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
|
|
|
28
28
|
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
@category
|
|
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>
|
package/source/pascal-case.d.ts
CHANGED
|
@@ -30,7 +30,8 @@ const dbResult: CamelCasedProperties<ModelProps> = {
|
|
|
30
30
|
};
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
@category
|
|
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
|
|
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
|
package/source/primitive.d.ts
CHANGED
package/source/promisable.d.ts
CHANGED
|
@@ -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>;
|
|
@@ -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.
|
|
@@ -22,6 +24,6 @@ type RecursiveAsyncData = Promise<Promise<string> >;
|
|
|
22
24
|
let recursiveAsyncData: PromiseValue<RecursiveAsyncData> = Promise.resolve(Promise.resolve('ABC'));
|
|
23
25
|
```
|
|
24
26
|
|
|
25
|
-
@category
|
|
27
|
+
@category Async
|
|
26
28
|
*/
|
|
27
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
|
|
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
|
|
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.
|
|
@@ -23,7 +23,8 @@ import {ScreamingSnakeCase} from 'type-fest';
|
|
|
23
23
|
const someVariable: ScreamingSnakeCase<'fooBar'> = 'FOO_BAR';
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
@category
|
|
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
|
package/source/set-optional.d.ts
CHANGED
package/source/set-required.d.ts
CHANGED
|
@@ -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
|
|
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.
|
package/source/simplify.d.ts
CHANGED
package/source/snake-case.d.ts
CHANGED
|
@@ -38,6 +38,8 @@ const result: SnakeCasedPropertiesDeep<UserWithFriends> = {
|
|
|
38
38
|
};
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
@category
|
|
41
|
+
@category Change case
|
|
42
|
+
@category Template literal
|
|
43
|
+
@category Object
|
|
42
44
|
*/
|
|
43
45
|
export type SnakeCasedPropertiesDeep<Value> = DelimiterCasedPropertiesDeep<Value, '_'>;
|
package/source/split.d.ts
CHANGED
package/source/stringified.d.ts
CHANGED
package/source/trim.d.ts
CHANGED
|
@@ -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
|
|
|
@@ -1038,7 +1040,7 @@ declare namespace TsConfigJson {
|
|
|
1038
1040
|
/**
|
|
1039
1041
|
Type for [TypeScript's `tsconfig.json` file](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html) (TypeScript 3.7).
|
|
1040
1042
|
|
|
1041
|
-
@category
|
|
1043
|
+
@category File
|
|
1042
1044
|
*/
|
|
1043
1045
|
export interface TsConfigJson {
|
|
1044
1046
|
/**
|
package/source/typed-array.d.ts
CHANGED
|
@@ -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
|
|
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
|