type-fest 5.3.1 → 5.4.1
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 +3 -0
- package/package.json +4 -4
- package/readme.md +5 -0
- package/source/all-extend.d.ts +9 -6
- package/source/array-reverse.d.ts +84 -0
- package/source/array-slice.d.ts +1 -1
- package/source/array-splice.d.ts +3 -3
- package/source/conditional-pick-deep.d.ts +1 -1
- package/source/conditional-simplify-deep.d.ts +3 -3
- package/source/distributed-omit.d.ts +4 -4
- package/source/distributed-pick.d.ts +5 -5
- package/source/exact.d.ts +1 -1
- package/source/except.d.ts +5 -5
- package/source/exclusify-union.d.ts +41 -7
- package/source/fixed-length-array.d.ts +6 -6
- package/source/get.d.ts +9 -3
- package/source/int-closed-range.d.ts +2 -2
- package/source/int-range.d.ts +2 -2
- package/source/internal/object.d.ts +25 -1
- package/source/is-literal.d.ts +3 -2
- package/source/is-never.d.ts +2 -2
- package/source/is-unknown.d.ts +1 -1
- package/source/jsonifiable.d.ts +3 -5
- package/source/key-as-string.d.ts +1 -1
- package/source/merge-deep.d.ts +9 -9
- package/source/merge-exclusive.d.ts +3 -3
- package/source/merge.d.ts +4 -1
- package/source/non-empty-string.d.ts +3 -3
- package/source/non-empty-tuple.d.ts +2 -2
- package/source/numeric.d.ts +3 -3
- package/source/object-merge.d.ts +194 -0
- package/source/omit-deep.d.ts +6 -22
- package/source/omit-index-signature.d.ts +8 -4
- package/source/override-properties.d.ts +1 -1
- package/source/paths.d.ts +1 -1
- package/source/readonly-tuple.d.ts +2 -2
- package/source/required-deep.d.ts +2 -1
- package/source/schema.d.ts +10 -7
- package/source/set-non-nullable-deep.d.ts +1 -1
- package/source/set-parameter-type.d.ts +7 -7
- package/source/set-required-deep.d.ts +1 -7
- package/source/set-return-type.d.ts +1 -1
- package/source/split-on-rest-element.d.ts +2 -2
- package/source/subtract.d.ts +1 -1
- package/source/sum.d.ts +1 -1
- package/source/tuple-of.d.ts +1 -1
- package/source/tuple-to-object.d.ts +6 -6
- package/source/tuple-to-union.d.ts +1 -1
- package/source/union-to-intersection.d.ts +1 -1
- package/source/unknown-record.d.ts +6 -6
- package/source/unwrap-partial.d.ts +33 -0
- package/source/value-of.d.ts +2 -2
- package/source/words.d.ts +2 -2
|
@@ -13,27 +13,27 @@ Note: Tuple labels are [lost in the transformation process](https://stackoverflo
|
|
|
13
13
|
import type {TupleToObject} from 'type-fest';
|
|
14
14
|
|
|
15
15
|
type Example1 = TupleToObject<[number, string, boolean]>;
|
|
16
|
-
//=> {
|
|
16
|
+
//=> {0: number; 1: string; 2: boolean}
|
|
17
17
|
|
|
18
18
|
// Tuples with optional indices
|
|
19
19
|
type Example2 = TupleToObject<[number, string?, boolean?]>;
|
|
20
|
-
//=> {
|
|
20
|
+
//=> {0: number; 1?: string; 2?: boolean}
|
|
21
21
|
|
|
22
22
|
// Readonly tuples
|
|
23
23
|
type Example3 = TupleToObject<readonly [number, string?]>;
|
|
24
|
-
//=> {
|
|
24
|
+
//=> {readonly 0: number; readonly 1?: string}
|
|
25
25
|
|
|
26
26
|
// Non-tuple arrays get transformed into index signatures
|
|
27
27
|
type Example4 = TupleToObject<string[]>;
|
|
28
|
-
//=> {
|
|
28
|
+
//=> {[x: number]: string}
|
|
29
29
|
|
|
30
30
|
// Tuples with rest elements
|
|
31
31
|
type Example5 = TupleToObject<[number, string, ...boolean[]]>;
|
|
32
|
-
//=> {
|
|
32
|
+
//=> {[x: number]: string | number | boolean; 0: number; 1: string}
|
|
33
33
|
|
|
34
34
|
// Tuple labels are not preserved
|
|
35
35
|
type Example6 = TupleToObject<[x: number, y: number]>;
|
|
36
|
-
//=> {
|
|
36
|
+
//=> {0: number; 1: number}
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
@category Array
|
|
@@ -39,7 +39,7 @@ const erroringType = new Set(['a', 'b', 'c']);
|
|
|
39
39
|
|
|
40
40
|
// @ts-expect-error
|
|
41
41
|
type ErroringType = typeof erroringType[number];
|
|
42
|
-
|
|
42
|
+
// Error: Type 'Set<string>' has no matching index signature for type 'number'. ts(2537)
|
|
43
43
|
|
|
44
44
|
const numberBool: {[n: number]: boolean} = {1: true};
|
|
45
45
|
|
|
@@ -10,7 +10,7 @@ import type {UnionToIntersection} from 'type-fest';
|
|
|
10
10
|
type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
|
|
11
11
|
|
|
12
12
|
type Intersection = UnionToIntersection<Union>;
|
|
13
|
-
//=> {the(): void
|
|
13
|
+
//=> {the(): void} & {great(arg: string): void} & {escape: boolean}
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
@category Type
|
|
@@ -11,18 +11,18 @@ function toJson(object: UnknownRecord) {
|
|
|
11
11
|
return JSON.stringify(object);
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
toJson({hello: 'world'});
|
|
15
|
-
//=> '{"hello":"world"}'
|
|
14
|
+
toJson({hello: 'world'}); // Ok
|
|
16
15
|
|
|
17
16
|
function isObject(value: unknown): value is UnknownRecord {
|
|
18
17
|
return typeof value === 'object' && value !== null;
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
//=> true
|
|
20
|
+
const value: unknown = {hello: 'world'};
|
|
23
21
|
|
|
24
|
-
isObject(
|
|
25
|
-
|
|
22
|
+
if (isObject(value)) {
|
|
23
|
+
const v = value;
|
|
24
|
+
//=> UnknownRecord
|
|
25
|
+
}
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
@category Type
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
Revert the `Partial` modifier on an object type.
|
|
3
|
+
|
|
4
|
+
Use-case: Infer the underlying type `T` when only `Partial<T>` is available or the original type may not be directly accessible.
|
|
5
|
+
|
|
6
|
+
@example
|
|
7
|
+
```
|
|
8
|
+
import type {UnwrapPartial} from 'type-fest';
|
|
9
|
+
|
|
10
|
+
type Config = Partial<{
|
|
11
|
+
port: number;
|
|
12
|
+
host: string;
|
|
13
|
+
secure?: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
|
|
16
|
+
type InitializedConfig = UnwrapPartial<Config>;
|
|
17
|
+
//=> {port: number; host: string; secure?: boolean}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Note: If the provided type isn’t of `Partial<T>`, `UnwrapPartial` has no effect on the original type.
|
|
21
|
+
|
|
22
|
+
@category Object
|
|
23
|
+
*/
|
|
24
|
+
export type UnwrapPartial<PartialObjectType> =
|
|
25
|
+
PartialObjectType extends Partial<infer ObjectType>
|
|
26
|
+
? (
|
|
27
|
+
Partial<ObjectType> extends PartialObjectType
|
|
28
|
+
? ObjectType
|
|
29
|
+
: PartialObjectType
|
|
30
|
+
)
|
|
31
|
+
: PartialObjectType;
|
|
32
|
+
|
|
33
|
+
export {};
|
package/source/value-of.d.ts
CHANGED
|
@@ -8,13 +8,13 @@ Please upvote [this issue](https://github.com/microsoft/TypeScript/issues/31438)
|
|
|
8
8
|
import type {ValueOf} from 'type-fest';
|
|
9
9
|
|
|
10
10
|
type A = ValueOf<{id: number; name: string; active: boolean}>;
|
|
11
|
-
//=>
|
|
11
|
+
//=> string | number | boolean
|
|
12
12
|
|
|
13
13
|
type B = ValueOf<{id: number; name: string; active: boolean}, 'name'>;
|
|
14
14
|
//=> string
|
|
15
15
|
|
|
16
16
|
type C = ValueOf<{id: number; name: string; active: boolean}, 'id' | 'name'>;
|
|
17
|
-
//=>
|
|
17
|
+
//=> string | number
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
@category Object
|
package/source/words.d.ts
CHANGED
|
@@ -31,10 +31,10 @@ export type WordsOptions = {
|
|
|
31
31
|
import type {Words} from 'type-fest';
|
|
32
32
|
|
|
33
33
|
type Example1 = Words<'p2pNetwork', {splitOnNumbers: true}>;
|
|
34
|
-
//=> [
|
|
34
|
+
//=> ['p', '2', 'p', 'Network']
|
|
35
35
|
|
|
36
36
|
type Example2 = Words<'p2pNetwork', {splitOnNumbers: false}>;
|
|
37
|
-
//=> [
|
|
37
|
+
//=> ['p2p', 'Network']
|
|
38
38
|
```
|
|
39
39
|
*/
|
|
40
40
|
splitOnNumbers?: boolean;
|