type-fest 2.0.0 → 2.1.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/package.json +1 -1
- package/readme.md +1 -1
- package/source/camel-case.d.ts +2 -2
- package/source/delimiter-case.d.ts +1 -1
- package/source/entries.d.ts +1 -1
- package/source/entry.d.ts +1 -1
- package/source/includes.d.ts +2 -2
- package/source/last-array-element.d.ts +2 -2
- package/source/observable-like.d.ts +3 -3
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -121,7 +121,7 @@ Click the type names for complete docs.
|
|
|
121
121
|
- [`Entries`](source/entries.d.ts) - Create a type that represents the type of the entries of a collection.
|
|
122
122
|
- [`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.
|
|
123
123
|
- [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type.
|
|
124
|
-
- [`Includes`](source/includes.ts) - Returns a boolean for whether the given array includes the given item.
|
|
124
|
+
- [`Includes`](source/includes.d.ts) - Returns a boolean for whether the given array includes the given item.
|
|
125
125
|
- [`Simplify`](source/simplify.d.ts) - Flatten the type output to improve type hints shown in editors.
|
|
126
126
|
- [`Jsonify`](source/jsonify.d.ts) - Transform a type to one that is assignable to the `JsonValue` type.
|
|
127
127
|
|
package/source/camel-case.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ Only to be used by `CamelCaseStringArray<>`.
|
|
|
8
8
|
|
|
9
9
|
@see CamelCaseStringArray
|
|
10
10
|
*/
|
|
11
|
-
type InnerCamelCaseStringArray<Parts extends any[], PreviousPart> =
|
|
11
|
+
type InnerCamelCaseStringArray<Parts extends readonly any[], PreviousPart> =
|
|
12
12
|
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
|
|
13
13
|
? FirstPart extends undefined
|
|
14
14
|
? ''
|
|
@@ -24,7 +24,7 @@ It's separate from `InnerCamelCaseStringArray<>` to keep a clean API outwards to
|
|
|
24
24
|
|
|
25
25
|
@see Split
|
|
26
26
|
*/
|
|
27
|
-
type CamelCaseStringArray<Parts extends string[]> =
|
|
27
|
+
type CamelCaseStringArray<Parts extends readonly string[]> =
|
|
28
28
|
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
|
|
29
29
|
? Uncapitalize<`${FirstPart}${InnerCamelCaseStringArray<RemainingParts, FirstPart>}`>
|
|
30
30
|
: never;
|
|
@@ -36,7 +36,7 @@ It receives `UsedWordSeparators` and `UsedUpperCaseCharacters` as input to ensur
|
|
|
36
36
|
|
|
37
37
|
@see SplitIncludingDelimiters
|
|
38
38
|
*/
|
|
39
|
-
type StringArrayToDelimiterCase<Parts extends any[], UsedWordSeparators extends string, UsedUpperCaseCharacters extends string, Delimiter extends string> =
|
|
39
|
+
type StringArrayToDelimiterCase<Parts extends readonly any[], UsedWordSeparators extends string, UsedUpperCaseCharacters extends string, Delimiter extends string> =
|
|
40
40
|
Parts extends [`${infer FirstPart}`, ...infer RemainingParts]
|
|
41
41
|
? `${StringPartToDelimiterCase<FirstPart, UsedWordSeparators, UsedUpperCaseCharacters, Delimiter>}${StringArrayToDelimiterCase<RemainingParts, UsedWordSeparators, UsedUpperCaseCharacters, Delimiter>}`
|
|
42
42
|
: '';
|
package/source/entries.d.ts
CHANGED
|
@@ -54,6 +54,6 @@ const setEntries: Entries<typeof setExample> = [['a', 'a'], [1, 1]];
|
|
|
54
54
|
export type Entries<BaseType> =
|
|
55
55
|
BaseType extends Map<unknown, unknown> ? MapEntries<BaseType>
|
|
56
56
|
: BaseType extends Set<unknown> ? SetEntries<BaseType>
|
|
57
|
-
: BaseType extends unknown[] ? ArrayEntries<BaseType>
|
|
57
|
+
: BaseType extends readonly unknown[] ? ArrayEntries<BaseType>
|
|
58
58
|
: BaseType extends object ? ObjectEntries<BaseType>
|
|
59
59
|
: never;
|
package/source/entry.d.ts
CHANGED
|
@@ -57,6 +57,6 @@ const setEntryNumber: Entry<typeof setExample> = [1, 1];
|
|
|
57
57
|
export type Entry<BaseType> =
|
|
58
58
|
BaseType extends Map<unknown, unknown> ? MapEntry<BaseType>
|
|
59
59
|
: BaseType extends Set<unknown> ? SetEntry<BaseType>
|
|
60
|
-
: BaseType extends unknown[] ? ArrayEntry<BaseType>
|
|
60
|
+
: BaseType extends readonly unknown[] ? ArrayEntry<BaseType>
|
|
61
61
|
: BaseType extends object ? ObjectEntry<BaseType>
|
|
62
62
|
: never;
|
package/source/includes.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
Returns a boolean for whether
|
|
2
|
+
Returns a boolean for whether the two given types are equal.
|
|
3
3
|
|
|
4
4
|
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
5
5
|
*/
|
|
@@ -23,7 +23,7 @@ type hasRed<array extends any[]> = Includes<array, 'red'>;
|
|
|
23
23
|
|
|
24
24
|
@category Utilities
|
|
25
25
|
*/
|
|
26
|
-
export type Includes<Value extends any[], Item> =
|
|
26
|
+
export type Includes<Value extends readonly any[], Item> =
|
|
27
27
|
IsEqual<Value[0], Item> extends true
|
|
28
28
|
? true
|
|
29
29
|
: Value extends [Value[0], ...infer rest]
|
|
@@ -7,7 +7,7 @@ Use-case: Defining the return type of functions that extract the last element of
|
|
|
7
7
|
```
|
|
8
8
|
import {LastArrayElement} from 'type-fest';
|
|
9
9
|
|
|
10
|
-
declare function lastOf<V extends any[]>(array: V): LastArrayElement<V>;
|
|
10
|
+
declare function lastOf<V extends readonly any[]>(array: V): LastArrayElement<V>;
|
|
11
11
|
|
|
12
12
|
const array = ['foo', 2];
|
|
13
13
|
|
|
@@ -17,7 +17,7 @@ typeof lastOf(array);
|
|
|
17
17
|
|
|
18
18
|
@category Template Literals
|
|
19
19
|
*/
|
|
20
|
-
export type LastArrayElement<ValueType extends unknown[]> =
|
|
20
|
+
export type LastArrayElement<ValueType extends readonly unknown[]> =
|
|
21
21
|
ValueType extends [infer ElementType]
|
|
22
22
|
? ElementType
|
|
23
23
|
: ValueType extends [infer _, ...infer Tail]
|
|
@@ -9,7 +9,7 @@ Matches a value that is like an [Observable](https://github.com/tc39/proposal-ob
|
|
|
9
9
|
|
|
10
10
|
@category Basic
|
|
11
11
|
*/
|
|
12
|
-
export interface ObservableLike {
|
|
13
|
-
subscribe(observer: (value:
|
|
14
|
-
[Symbol.observable](): ObservableLike
|
|
12
|
+
export interface ObservableLike<ValueType = unknown> {
|
|
13
|
+
subscribe(observer: (value: ValueType) => void): void;
|
|
14
|
+
[Symbol.observable](): ObservableLike<ValueType>;
|
|
15
15
|
}
|