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.
- package/index.d.ts +2 -0
- package/package.json +1 -1
- package/readme.md +35 -21
- 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 +3 -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 +40 -8
- 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 +1 -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 +1 -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
package/package.json
CHANGED
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
|
-
- [`
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
- [`
|
|
136
|
-
- [`
|
|
137
|
-
- [`
|
|
138
|
-
|
|
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
|
-
|
|
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
|
|
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 '' ? [] :
|
|
@@ -79,7 +79,8 @@ const rawCliOptions: OddlyCasedProperties<SomeOptions> = {
|
|
|
79
79
|
};
|
|
80
80
|
```
|
|
81
81
|
|
|
82
|
-
@category
|
|
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<
|
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
package/source/numeric.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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>;
|
|
@@ -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
|
|
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
|
|
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
|
@@ -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
|
|
1043
|
+
@category File
|
|
1044
1044
|
*/
|
|
1045
1045
|
export interface TsConfigJson {
|
|
1046
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
|