type-fest 3.13.1 → 4.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/index.d.ts +2 -7
- package/package.json +3 -3
- package/readme.md +14 -1
- package/source/internal.d.ts +5 -0
- package/source/jsonify.d.ts +15 -5
- package/source/last-array-element.d.ts +7 -7
- package/source/package-json.d.ts +1 -1
- package/source/require-all-or-none.d.ts +10 -4
- package/source/require-one-or-none.d.ts +37 -0
package/index.d.ts
CHANGED
|
@@ -16,13 +16,8 @@ export type {MergeExclusive} from './source/merge-exclusive';
|
|
|
16
16
|
export type {RequireAtLeastOne} from './source/require-at-least-one';
|
|
17
17
|
export type {RequireExactlyOne} from './source/require-exactly-one';
|
|
18
18
|
export type {RequireAllOrNone} from './source/require-all-or-none';
|
|
19
|
-
export type {
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
@deprecated Renamed to {@link OmitIndexSignature}.
|
|
23
|
-
*/
|
|
24
|
-
OmitIndexSignature as RemoveIndexSignature,
|
|
25
|
-
} from './source/omit-index-signature';
|
|
19
|
+
export type {RequireOneOrNone} from './source/require-one-or-none';
|
|
20
|
+
export type {OmitIndexSignature} from './source/omit-index-signature';
|
|
26
21
|
export type {PickIndexSignature} from './source/pick-index-signature';
|
|
27
22
|
export type {PartialDeep, PartialDeepOptions} from './source/partial-deep';
|
|
28
23
|
export type {RequiredDeep} from './source/required-deep';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "type-fest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"description": "A collection of essential TypeScript types",
|
|
5
5
|
"license": "(MIT OR CC0-1.0)",
|
|
6
6
|
"repository": "sindresorhus/type-fest",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
},
|
|
13
13
|
"types": "./index.d.ts",
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": ">=
|
|
15
|
+
"node": ">=16"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
18
|
"test": "xo && tsd && tsc && node script/test/source-files-extension.js"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"expect-type": "^0.15.0",
|
|
39
39
|
"tsd": "^0.28.1",
|
|
40
40
|
"typescript": "^5.0.4",
|
|
41
|
-
"xo": "^0.
|
|
41
|
+
"xo": "^0.55.0"
|
|
42
42
|
},
|
|
43
43
|
"xo": {
|
|
44
44
|
"rules": {
|
package/readme.md
CHANGED
|
@@ -37,6 +37,18 @@
|
|
|
37
37
|
<sup>Add Single Sign-On (and more) in minutes instead of months.</sup>
|
|
38
38
|
</div>
|
|
39
39
|
</a>
|
|
40
|
+
<br>
|
|
41
|
+
<br>
|
|
42
|
+
<br>
|
|
43
|
+
<a href="https://transloadit.com?utm_source=sindresorhus&utm_medium=referral&utm_campaign=sponsorship&utm_content=type-fest">
|
|
44
|
+
<picture>
|
|
45
|
+
<source width="350" media="(prefers-color-scheme: dark)" srcset="https://sindresorhus.com/assets/thanks/transloadit-logo-dark.svg">
|
|
46
|
+
<source width="350" media="(prefers-color-scheme: light)" srcset="https://sindresorhus.com/assets/thanks/transloadit-logo.svg">
|
|
47
|
+
<img width="350" src="https://sindresorhus.com/assets/thanks/transloadit-logo.svg" alt="Transloadit logo">
|
|
48
|
+
</picture>
|
|
49
|
+
</a>
|
|
50
|
+
<br>
|
|
51
|
+
<br>
|
|
40
52
|
</p>
|
|
41
53
|
</div>
|
|
42
54
|
<br>
|
|
@@ -64,7 +76,7 @@ PR welcome for additional commonly needed types and docs improvements. Read the
|
|
|
64
76
|
npm install type-fest
|
|
65
77
|
```
|
|
66
78
|
|
|
67
|
-
*Requires TypeScript >=
|
|
79
|
+
*Requires TypeScript >=5.1*
|
|
68
80
|
|
|
69
81
|
## Usage
|
|
70
82
|
|
|
@@ -108,6 +120,7 @@ Click the type names for complete docs.
|
|
|
108
120
|
- [`RequireAtLeastOne`](source/require-at-least-one.d.ts) - Create a type that requires at least one of the given keys.
|
|
109
121
|
- [`RequireExactlyOne`](source/require-exactly-one.d.ts) - Create a type that requires exactly a single key of the given keys and disallows more.
|
|
110
122
|
- [`RequireAllOrNone`](source/require-all-or-none.d.ts) - Create a type that requires all of the given keys or none of the given keys.
|
|
123
|
+
- [`RequireOneOrNone`](source/require-one-or-none.d.ts) - Create a type that requires exactly a single key of the given keys and disallows more, or none of the given keys.
|
|
111
124
|
- [`RequiredDeep`](source/required-deep.d.ts) - Create a deeply required version of another type. Use [`Required<T>`](https://www.typescriptlang.org/docs/handbook/utility-types.html#requiredtype) if you only need one level deep.
|
|
112
125
|
- [`OmitIndexSignature`](source/omit-index-signature.d.ts) - Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
113
126
|
- [`PickIndexSignature`](source/pick-index-signature.d.ts) - Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
package/source/internal.d.ts
CHANGED
|
@@ -251,3 +251,8 @@ export type IsNotFalse<T extends boolean> = [T] extends [false] ? false : true;
|
|
|
251
251
|
Returns a boolean for whether the given type is `null`.
|
|
252
252
|
*/
|
|
253
253
|
export type IsNull<T> = [T] extends [null] ? true : false;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
Disallows any of the given keys.
|
|
257
|
+
*/
|
|
258
|
+
export type RequireNone<KeysType extends PropertyKey> = Partial<Record<KeysType, never>>;
|
package/source/jsonify.d.ts
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import type {JsonPrimitive, JsonValue} from './basic';
|
|
2
2
|
import type {EmptyObject} from './empty-object';
|
|
3
3
|
import type {UndefinedToOptional} from './internal';
|
|
4
|
+
import type {IsAny} from './is-any';
|
|
5
|
+
import type {IsNever} from './is-never';
|
|
4
6
|
import type {NegativeInfinity, PositiveInfinity} from './numeric';
|
|
5
7
|
import type {TypedArray} from './typed-array';
|
|
6
|
-
import type {IsAny} from './is-any';
|
|
7
8
|
|
|
8
9
|
// Note: The return value has to be `any` and not `unknown` so it can match `void`.
|
|
9
10
|
type NotJsonable = ((...arguments_: any[]) => any) | undefined | symbol;
|
|
10
11
|
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
type FilterNonNever<T extends unknown[]> = T extends [infer F, ...infer R]
|
|
13
|
+
? IsNever<F> extends true
|
|
14
|
+
? FilterNonNever<R>
|
|
15
|
+
: [F, ...FilterNonNever<R>]
|
|
16
|
+
: IsNever<T[number]> extends true
|
|
17
|
+
? []
|
|
18
|
+
: T;
|
|
19
|
+
|
|
20
|
+
// Handles tuples and arrays
|
|
21
|
+
type JsonifyList<T extends unknown[]> = T extends [infer F, ...infer R]
|
|
22
|
+
? FilterNonNever<[Jsonify<F>, ...JsonifyList<R>]>
|
|
23
|
+
: Array<Jsonify<T[number]>>;
|
|
14
24
|
|
|
15
25
|
type FilterJsonableKeys<T extends object> = {
|
|
16
26
|
[Key in keyof T]: T[Key] extends NotJsonable ? never : Key;
|
|
@@ -107,7 +117,7 @@ export type Jsonify<T> = IsAny<T> extends true
|
|
|
107
117
|
: T extends []
|
|
108
118
|
? []
|
|
109
119
|
: T extends [unknown, ...unknown[]]
|
|
110
|
-
?
|
|
120
|
+
? JsonifyList<T>
|
|
111
121
|
: T extends ReadonlyArray<infer U>
|
|
112
122
|
? Array<U extends NotJsonable ? null : Jsonify<U>>
|
|
113
123
|
: T extends object
|
|
@@ -18,11 +18,11 @@ typeof lastOf(array);
|
|
|
18
18
|
@category Array
|
|
19
19
|
@category Template literal
|
|
20
20
|
*/
|
|
21
|
-
export type LastArrayElement<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
:
|
|
27
|
-
?
|
|
21
|
+
export type LastArrayElement<Elements extends readonly unknown[]>
|
|
22
|
+
= number extends Elements['length']
|
|
23
|
+
? Elements extends ReadonlyArray<infer Element>
|
|
24
|
+
? Element
|
|
25
|
+
: never
|
|
26
|
+
: Elements extends readonly [...any, infer Target]
|
|
27
|
+
? Target
|
|
28
28
|
: never;
|
package/source/package-json.d.ts
CHANGED
|
@@ -505,7 +505,7 @@ declare namespace PackageJson {
|
|
|
505
505
|
Engines that this package runs on.
|
|
506
506
|
*/
|
|
507
507
|
engines?: {
|
|
508
|
-
[EngineName in 'npm' | 'node' | string]?: string;
|
|
508
|
+
[EngineName in 'npm' | 'node' | string]?: string;
|
|
509
509
|
};
|
|
510
510
|
|
|
511
511
|
/**
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import type {RequireNone} from './internal';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Requires all of the keys in the given object.
|
|
5
|
+
*/
|
|
6
|
+
type RequireAll<ObjectType, KeysType extends keyof ObjectType> = Required<Pick<ObjectType, KeysType>>;
|
|
7
|
+
|
|
1
8
|
/**
|
|
2
9
|
Create a type that requires all of the given keys or none of the given keys. The remaining keys are kept as is.
|
|
3
10
|
|
|
@@ -30,7 +37,6 @@ const responder2: RequireAllOrNone<Responder, 'text' | 'json'> = {
|
|
|
30
37
|
@category Object
|
|
31
38
|
*/
|
|
32
39
|
export type RequireAllOrNone<ObjectType, KeysType extends keyof ObjectType = never> = (
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
) &
|
|
36
|
-
Omit<ObjectType, KeysType>; // The rest of the keys.
|
|
40
|
+
| RequireAll<ObjectType, KeysType>
|
|
41
|
+
| RequireNone<KeysType>
|
|
42
|
+
) & Omit<ObjectType, KeysType>; // The rest of the keys.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type {RequireExactlyOne} from './require-exactly-one';
|
|
2
|
+
import type {RequireNone} from './internal';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Create a type that requires exactly one of the given keys and disallows more, or none of the given keys. The remaining keys are kept as is.
|
|
6
|
+
|
|
7
|
+
@example
|
|
8
|
+
```
|
|
9
|
+
import type {RequireOneOrNone} from 'type-fest';
|
|
10
|
+
|
|
11
|
+
type Responder = RequireOneOrNone<{
|
|
12
|
+
text: () => string;
|
|
13
|
+
json: () => string;
|
|
14
|
+
secure: boolean;
|
|
15
|
+
}, 'text' | 'json'>;
|
|
16
|
+
|
|
17
|
+
const responder1: Responder = {
|
|
18
|
+
secure: true
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const responder2: Responder = {
|
|
22
|
+
text: () => '{"message": "hi"}',
|
|
23
|
+
secure: true
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const responder3: Responder = {
|
|
27
|
+
json: () => '{"message": "ok"}',
|
|
28
|
+
secure: true
|
|
29
|
+
};
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
@category Object
|
|
33
|
+
*/
|
|
34
|
+
export type RequireOneOrNone<ObjectType, KeysType extends keyof ObjectType = keyof ObjectType> = (
|
|
35
|
+
| RequireExactlyOne<ObjectType, KeysType>
|
|
36
|
+
| RequireNone<KeysType>
|
|
37
|
+
) & Omit<ObjectType, KeysType>; // Ignore unspecified keys.
|