type-fest 4.0.0 → 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 CHANGED
@@ -16,6 +16,7 @@ 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 {RequireOneOrNone} from './source/require-one-or-none';
19
20
  export type {OmitIndexSignature} from './source/omit-index-signature';
20
21
  export type {PickIndexSignature} from './source/pick-index-signature';
21
22
  export type {PartialDeep, PartialDeepOptions} from './source/partial-deep';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "4.0.0",
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",
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>
@@ -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.
@@ -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>>;
@@ -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
- | Required<Pick<ObjectType, KeysType>> // Require all of the given keys.
34
- | Partial<Record<KeysType, never>> // Require none of the given keys.
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.