type-fest 2.5.4 → 2.9.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 +13 -0
- package/package.json +1 -1
- package/readme.md +44 -18
- 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 +48 -10
- 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 +2 -2
- 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-to-primitive.d.ts +36 -0
- 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,19 @@ 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 {LiteralToPrimitive} from './source/literal-to-primitive';
|
|
41
|
+
export {
|
|
42
|
+
PositiveInfinity,
|
|
43
|
+
NegativeInfinity,
|
|
44
|
+
Finite,
|
|
45
|
+
Integer,
|
|
46
|
+
Float,
|
|
47
|
+
NegativeFloat,
|
|
48
|
+
Negative,
|
|
49
|
+
NonNegative,
|
|
50
|
+
NegativeInteger,
|
|
51
|
+
NonNegativeInteger,
|
|
52
|
+
} from './source/numeric';
|
|
40
53
|
|
|
41
54
|
// Template literal types
|
|
42
55
|
export {CamelCase} from './source/camel-case';
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -88,10 +88,6 @@ Click the type names for complete docs.
|
|
|
88
88
|
- [`Class`](source/basic.d.ts) - Matches a [`class`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
89
89
|
- [`Constructor`](source/basic.d.ts) - Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
|
|
90
90
|
- [`TypedArray`](source/typed-array.d.ts) - Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.
|
|
91
|
-
- [`JsonPrimitive`](source/basic.d.ts) - Matches a JSON primitive.
|
|
92
|
-
- [`JsonObject`](source/basic.d.ts) - Matches a JSON object.
|
|
93
|
-
- [`JsonArray`](source/basic.d.ts) - Matches a JSON array.
|
|
94
|
-
- [`JsonValue`](source/basic.d.ts) - Matches any valid JSON value.
|
|
95
91
|
- [`ObservableLike`](source/observable-like.d.ts) - Matches a value that is like an [Observable](https://github.com/tc39/proposal-observable).
|
|
96
92
|
|
|
97
93
|
### Utilities
|
|
@@ -106,31 +102,65 @@ Click the type names for complete docs.
|
|
|
106
102
|
- [`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
103
|
- [`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
104
|
- [`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
105
|
- [`Opaque`](source/opaque.d.ts) - Create an [opaque type](https://codemix.com/opaque-types-in-javascript/).
|
|
111
106
|
- [`SetOptional`](source/set-optional.d.ts) - Create a type that makes the given keys optional.
|
|
112
107
|
- [`SetRequired`](source/set-required.d.ts) - Create a type that makes the given keys required.
|
|
113
108
|
- [`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
109
|
- [`ConditionalKeys`](source/conditional-keys.d.ts) - Extract keys from a shape where values extend the given `Condition` type.
|
|
117
110
|
- [`ConditionalPick`](source/conditional-pick.d.ts) - Like `Pick` except it selects properties from a shape where the values extend the given `Condition` type.
|
|
118
111
|
- [`ConditionalExcept`](source/conditional-except.d.ts) - Like `Omit` except it removes properties from a shape where the values extend the given `Condition` type.
|
|
119
112
|
- [`UnionToIntersection`](source/union-to-intersection.d.ts) - Convert a union type to an intersection type.
|
|
113
|
+
- [`LiteralToPrimitive`](source/literal-to-primitive.d.ts) - Convert a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) to the [primitive type](source/primitive.d.ts) it belongs to.
|
|
120
114
|
- [`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
115
|
- [`IterableElement`](source/iterable-element.d.ts) - Get the element type of an `Iterable`/`AsyncIterable`. For example, an array or a generator.
|
|
125
116
|
- [`Entry`](source/entry.d.ts) - Create a type that represents the type of an entry of a collection.
|
|
126
117
|
- [`Entries`](source/entries.d.ts) - Create a type that represents the type of the entries of a collection.
|
|
127
118
|
- [`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
119
|
- [`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.
|
|
120
|
+
- [`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.
|
|
121
|
+
|
|
122
|
+
### JSON
|
|
123
|
+
|
|
131
124
|
- [`Jsonify`](source/jsonify.d.ts) - Transform a type to one that is assignable to the `JsonValue` type.
|
|
125
|
+
- [`JsonPrimitive`](source/basic.d.ts) - Matches a JSON primitive.
|
|
126
|
+
- [`JsonObject`](source/basic.d.ts) - Matches a JSON object.
|
|
127
|
+
- [`JsonArray`](source/basic.d.ts) - Matches a JSON array.
|
|
128
|
+
- [`JsonValue`](source/basic.d.ts) - Matches any valid JSON value.
|
|
129
|
+
|
|
130
|
+
### Async
|
|
131
|
+
|
|
132
|
+
- [`Promisable`](source/promisable.d.ts) - Create a type that represents either the value or the value wrapped in `PromiseLike`.
|
|
133
|
+
- [`AsyncReturnType`](source/async-return-type.d.ts) - Unwrap the return type of a function that returns a `Promise`.
|
|
134
|
+
- [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type.
|
|
135
|
+
|
|
136
|
+
### String
|
|
137
|
+
|
|
138
|
+
- [`Trim`](source/trim.d.ts) - Remove leading and trailing spaces from a string.
|
|
139
|
+
- [`Split`](source/split.d.ts) - Represents an array of strings split using a given character or character set.
|
|
132
140
|
|
|
133
|
-
###
|
|
141
|
+
### Array
|
|
142
|
+
|
|
143
|
+
- [`Includes`](source/includes.d.ts) - Returns a boolean for whether the given array includes the given item.
|
|
144
|
+
- [`Join`](source/join.d.ts) - Join an array of strings and/or numbers using the given string as a delimiter.
|
|
145
|
+
- [`LastArrayElement`](source/last-array-element.d.ts) - Extracts the type of the last element of an array.
|
|
146
|
+
- [`FixedLengthArray`](source/fixed-length-array.d.ts) - Create a type that represents an array of the given type and length.
|
|
147
|
+
- [`MultidimensionalArray`](source/multidimensional-array.d.ts) - Create a type that represents a multidimensional array of the given type and dimensions.
|
|
148
|
+
- [`MultidimensionalReadonlyArray`](source/multidimensional-readonly-array.d.ts) - Create a type that represents a multidimensional readonly array of the given type and dimensions.
|
|
149
|
+
|
|
150
|
+
### Numeric
|
|
151
|
+
|
|
152
|
+
- [`PositiveInfinity`](source/numeric.d.ts) - Matches the hidden `Infinity` type.
|
|
153
|
+
- [`NegativeInfinity`](source/numeric.d.ts) - Matches the hidden `-Infinity` type.
|
|
154
|
+
- [`Finite`](source/numeric.d.ts) - A finite `number`.
|
|
155
|
+
- [`Integer`](source/numeric.d.ts) - A `number` that is an integer.
|
|
156
|
+
- [`Float`](source/numeric.d.ts) - A `number` that is not an integer.
|
|
157
|
+
- [`NegativeFloat`](source/numeric.d.ts) - A negative (`-∞ < x < 0`) `number` that is not an integer.
|
|
158
|
+
- [`Negative`](source/numeric.d.ts) - A negative `number`/`bigint` (`-∞ < x < 0`)
|
|
159
|
+
- [`NonNegative`](source/numeric.d.ts) - A non-negative `number`/`bigint` (`0 <= x < ∞`).
|
|
160
|
+
- [`NegativeInteger`](source/numeric.d.ts) - A negative (`-∞ < x < 0`) `number` that is an integer.
|
|
161
|
+
- [`NonNegativeInteger`](source/numeric.d.ts) - A non-negative (`0 <= x < ∞`) `number` that is an integer.
|
|
162
|
+
|
|
163
|
+
### Change case
|
|
134
164
|
|
|
135
165
|
- [`CamelCase`](source/camel-case.d.ts) – Convert a string literal to camel-case (`fooBar`).
|
|
136
166
|
- [`CamelCasedProperties`](source/camel-cased-properties.d.ts) – Convert object properties to camel-case (`fooBar`).
|
|
@@ -148,11 +178,6 @@ Click the type names for complete docs.
|
|
|
148
178
|
- [`DelimiterCase`](source/delimiter-case.d.ts) – Convert a string literal to a custom string delimiter casing.
|
|
149
179
|
- [`DelimiterCasedProperties`](source/delimiter-cased-properties.d.ts) – Convert object properties to a custom string delimiter casing.
|
|
150
180
|
- [`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
181
|
|
|
157
182
|
### Miscellaneous
|
|
158
183
|
|
|
@@ -167,6 +192,7 @@ Click the type names for complete docs.
|
|
|
167
192
|
- [`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
193
|
- [`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
194
|
- [`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.
|
|
195
|
+
- [`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
196
|
|
|
171
197
|
## Alternative type names
|
|
172
198
|
|
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
|
@@ -1,16 +1,43 @@
|
|
|
1
1
|
import {StringDigit} from '../source/utilities';
|
|
2
2
|
import {Split} from './split';
|
|
3
3
|
|
|
4
|
+
type GetOptions = {
|
|
5
|
+
strict?: boolean;
|
|
6
|
+
};
|
|
7
|
+
|
|
4
8
|
/**
|
|
5
9
|
Like the `Get` type but receives an array of strings as a path parameter.
|
|
6
10
|
*/
|
|
7
|
-
type GetWithPath<BaseType, Keys extends readonly string[]> =
|
|
11
|
+
type GetWithPath<BaseType, Keys extends readonly string[], Options extends GetOptions = {}> =
|
|
8
12
|
Keys extends []
|
|
9
13
|
? BaseType
|
|
10
14
|
: Keys extends [infer Head, ...infer Tail]
|
|
11
|
-
? GetWithPath<
|
|
15
|
+
? GetWithPath<
|
|
16
|
+
PropertyOf<BaseType, Extract<Head, string>, Options>,
|
|
17
|
+
Extract<Tail, string[]>,
|
|
18
|
+
Options
|
|
19
|
+
>
|
|
12
20
|
: never;
|
|
13
21
|
|
|
22
|
+
/**
|
|
23
|
+
Adds `undefined` to `Type` if `strict` is enabled.
|
|
24
|
+
*/
|
|
25
|
+
type Strictify<Type, Options extends GetOptions> =
|
|
26
|
+
Options['strict'] extends true ? Type | undefined : Type;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
If `Options['strict']` is `true`, includes `undefined` in the returned type when accessing properties on `Record<string, any>`.
|
|
30
|
+
|
|
31
|
+
Known limitations:
|
|
32
|
+
- Does not include `undefined` in the type on object types with an index signature (for example, `{a: string; [key: string]: string}`).
|
|
33
|
+
*/
|
|
34
|
+
type StrictPropertyOf<BaseType, Key extends keyof BaseType, Options extends GetOptions> =
|
|
35
|
+
Record<string, any> extends BaseType
|
|
36
|
+
? string extends keyof BaseType
|
|
37
|
+
? Strictify<BaseType[Key], Options> // Record<string, any>
|
|
38
|
+
: BaseType[Key] // Record<'a' | 'b', any> (Records with a string union as keys have required properties)
|
|
39
|
+
: BaseType[Key];
|
|
40
|
+
|
|
14
41
|
/**
|
|
15
42
|
Splits a dot-prop style path into a tuple comprised of the properties in the path. Handles square-bracket notation.
|
|
16
43
|
|
|
@@ -29,8 +56,12 @@ type ToPath<S extends string> = Split<FixPathSquareBrackets<S>, '.'>;
|
|
|
29
56
|
Replaces square-bracketed dot notation with dots, for example, `foo[0].bar` -> `foo.0.bar`.
|
|
30
57
|
*/
|
|
31
58
|
type FixPathSquareBrackets<Path extends string> =
|
|
32
|
-
Path extends
|
|
33
|
-
?
|
|
59
|
+
Path extends `[${infer Head}]${infer Tail}`
|
|
60
|
+
? Tail extends `[${string}`
|
|
61
|
+
? `${Head}.${FixPathSquareBrackets<Tail>}`
|
|
62
|
+
: `${Head}${FixPathSquareBrackets<Tail>}`
|
|
63
|
+
: Path extends `${infer Head}[${infer Middle}]${infer Tail}`
|
|
64
|
+
? `${Head}.${FixPathSquareBrackets<`[${Middle}]${Tail}`>}`
|
|
34
65
|
: Path;
|
|
35
66
|
|
|
36
67
|
/**
|
|
@@ -76,11 +107,11 @@ Note:
|
|
|
76
107
|
- Returns `unknown` if `Key` is not a property of `BaseType`, since TypeScript uses structural typing, and it cannot be guaranteed that extra properties unknown to the type system will exist at runtime.
|
|
77
108
|
- Returns `undefined` from nullish values, to match the behaviour of most deep-key libraries like `lodash`, `dot-prop`, etc.
|
|
78
109
|
*/
|
|
79
|
-
type PropertyOf<BaseType, Key extends string> =
|
|
110
|
+
type PropertyOf<BaseType, Key extends string, Options extends GetOptions = {}> =
|
|
80
111
|
BaseType extends null | undefined
|
|
81
112
|
? undefined
|
|
82
113
|
: Key extends keyof BaseType
|
|
83
|
-
? BaseType
|
|
114
|
+
? StrictPropertyOf<BaseType, Key, Options>
|
|
84
115
|
: BaseType extends [] | [unknown, ...unknown[]]
|
|
85
116
|
? unknown // It's a tuple, but `Key` did not extend `keyof BaseType`. So the index is out of bounds.
|
|
86
117
|
: BaseType extends {
|
|
@@ -89,11 +120,11 @@ type PropertyOf<BaseType, Key extends string> =
|
|
|
89
120
|
}
|
|
90
121
|
? (
|
|
91
122
|
ConsistsOnlyOf<Key, StringDigit> extends true
|
|
92
|
-
? Item
|
|
123
|
+
? Strictify<Item, Options>
|
|
93
124
|
: unknown
|
|
94
125
|
)
|
|
95
126
|
: Key extends keyof WithStringKeys<BaseType>
|
|
96
|
-
? WithStringKeys<BaseType>
|
|
127
|
+
? StrictPropertyOf<WithStringKeys<BaseType>, Key, Options>
|
|
97
128
|
: unknown;
|
|
98
129
|
|
|
99
130
|
// This works by first splitting the path based on `.` and `[...]` characters into a tuple of string keys. Then it recursively uses the head key to get the next property of the current object, until there are no keys left. Number keys extract the item type from arrays, or are converted to strings to extract types from tuples and dictionaries with number keys.
|
|
@@ -128,8 +159,15 @@ interface ApiResponse {
|
|
|
128
159
|
const getName = (apiResponse: ApiResponse) =>
|
|
129
160
|
get(apiResponse, 'hits.hits[0]._source.name');
|
|
130
161
|
//=> Array<{given: string[]; family: string}>
|
|
162
|
+
|
|
163
|
+
// Strict mode:
|
|
164
|
+
Get<string[], '3', {strict: true}> //=> string | undefined
|
|
165
|
+
Get<Record<string, string>, 'foo', {strict: true}> // => string | undefined
|
|
131
166
|
```
|
|
132
167
|
|
|
133
|
-
@category
|
|
168
|
+
@category Object
|
|
169
|
+
@category Array
|
|
170
|
+
@category Template literal
|
|
134
171
|
*/
|
|
135
|
-
export type Get<BaseType, Path extends string
|
|
172
|
+
export type Get<BaseType, Path extends string, Options extends GetOptions = {}> =
|
|
173
|
+
GetWithPath<BaseType, ToPath<Path>, Options>;
|
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.
|
|
@@ -70,6 +70,6 @@ type Jsonify<T> =
|
|
|
70
70
|
? (() => J) extends (() => JsonValue) // Is J assignable to JsonValue?
|
|
71
71
|
? J // Then T is Jsonable and its Jsonable value is J
|
|
72
72
|
: never // Not Jsonable because its toJSON() method does not return JsonValue
|
|
73
|
-
: {[P in keyof T]: Jsonify<T[P]>} // It's an object: recursive call for its children
|
|
73
|
+
: {[P in keyof T]: Jsonify<Required<T>[P]>} // It's an object: recursive call for its children
|
|
74
74
|
: never // Otherwise any other non-object is removed
|
|
75
75
|
: never; // Otherwise non-JSONable type union was found not empty
|
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, '-'>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Given a [literal type](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#literal-types) return the {@link Primitive | primitive type} it belongs to, or `never` if it's not a primitive.
|
|
3
|
+
|
|
4
|
+
Use-case: Working with generic types that may be literal types.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import {LiteralToPrimitive} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
// No overloads needed to get the correct return type
|
|
11
|
+
function plus<T extends number | bigint | string>(x: T, y: T): LiteralToPrimitive<T> {
|
|
12
|
+
return x + (y as any);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
plus('a', 'b'); // string
|
|
16
|
+
plus(1, 2); // number
|
|
17
|
+
plus(1n, 2n); // bigint
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
@category Type
|
|
21
|
+
*/
|
|
22
|
+
export type LiteralToPrimitive<T> = T extends number
|
|
23
|
+
? number
|
|
24
|
+
: T extends bigint
|
|
25
|
+
? bigint
|
|
26
|
+
: T extends string
|
|
27
|
+
? string
|
|
28
|
+
: T extends boolean
|
|
29
|
+
? boolean
|
|
30
|
+
: T extends symbol
|
|
31
|
+
? symbol
|
|
32
|
+
: T extends null
|
|
33
|
+
? null
|
|
34
|
+
: T extends undefined
|
|
35
|
+
? undefined
|
|
36
|
+
: never;
|
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
|