type-fest 4.17.0 → 4.18.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "type-fest",
3
- "version": "4.17.0",
3
+ "version": "4.18.0",
4
4
  "description": "A collection of essential TypeScript types",
5
5
  "license": "(MIT OR CC0-1.0)",
6
6
  "repository": "sindresorhus/type-fest",
@@ -39,10 +39,10 @@
39
39
  "generics"
40
40
  ],
41
41
  "devDependencies": {
42
- "expect-type": "^0.15.0",
42
+ "expect-type": "^0.19.0",
43
43
  "npm-run-all2": "^6.1.2",
44
44
  "tsd": "^0.31.0",
45
- "typescript": "~5.4.3",
45
+ "typescript": "~5.4.5",
46
46
  "xo": "^0.58.0"
47
47
  },
48
48
  "xo": {
package/readme.md CHANGED
@@ -151,10 +151,8 @@ Click the type names for complete docs.
151
151
  - [`UndefinedOnPartialDeep`](source/undefined-on-partial-deep.d.ts) - Create a deep version of another type where all optional keys are set to also accept `undefined`.
152
152
  - [`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.
153
153
  - [`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).
154
- - [`Tagged`](source/opaque.d.ts) - Create a [tagged type](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d) that can support [multiple tags](https://github.com/sindresorhus/type-fest/issues/665) if needed.
155
- - [`UnwrapTagged`](source/opaque.d.ts) - Get the untagged portion of a tagged type created with `Tagged`.
156
- - [`Opaque`](source/opaque.d.ts) - Create a [tagged type](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d). This implementation only supports a single tag.
157
- - [`UnwrapOpaque`](source/opaque.d.ts) - Get the untagged portion of a tagged type created with `Opaque` or `Tagged`.
154
+ - [`Tagged`](source/opaque.d.ts) - Create a [tagged type](https://medium.com/@KevinBGreene/surviving-the-typescript-ecosystem-branding-and-type-tagging-6cf6e516523d) that can support [multiple tags](https://github.com/sindresorhus/type-fest/issues/665) and [per-tag metadata](https://medium.com/@ethanresnick/advanced-typescript-tagged-types-improved-with-type-level-metadata-5072fc125fcf). (This replaces the previous [`Opaque`](source/opaque.d.ts) type, which is now deprecated.)
155
+ - [`UnwrapTagged`](source/opaque.d.ts) - Get the untagged portion of a tagged type created with `Tagged`. (This replaces the previous [`UnwrapOpaque`](source/opaque.d.ts) type, which is now deprecated.)
158
156
  - [`InvariantOf`](source/invariant-of.d.ts) - Create an [invariant type](https://basarat.gitbook.io/typescript/type-system/type-compatibility#footnote-invariance), which is a type that does not accept supertypes and subtypes.
159
157
  - [`SetOptional`](source/set-optional.d.ts) - Create a type that makes the given keys optional.
160
158
  - [`SetReadonly`](source/set-readonly.d.ts) - Create a type that makes the given keys readonly.
@@ -200,6 +198,8 @@ Click the type names for complete docs.
200
198
  - [`SharedUnionFieldsDeep`](source/shared-union-fields-deep.d.ts) - Create a type with shared fields from a union of object types, deeply traversing nested structures.
201
199
  - [`DistributedOmit`](source/distributed-omit.d.ts) - Omits keys from a type, distributing the operation over a union.
202
200
  - [`DistributedPick`](source/distributed-pick.d.ts) - Picks keys from a type, distributing the operation over a union.
201
+ - [`And`](source/and.d.ts) - Returns a boolean for whether two given types are both true.
202
+ - [`Or`](source/or.d.ts) - Returns a boolean for whether either of two given types are true.
203
203
 
204
204
  ### Type Guard
205
205
 
@@ -345,7 +345,8 @@ type ShouldBeNever = IfAny<'not any', 'not never', 'never'>;
345
345
  - `RequireOnlyOne` - See [`RequireExactlyOne`](source/require-exactly-one.d.ts)
346
346
  - `AtMostOne` - See [`RequireOneOrNone`](source/require-one-or-none.d.ts)
347
347
  - `AllKeys` - See [`KeysOfUnion`](source/keys-of-union.d.ts)
348
- - `Branded` - See [`Opaque`](source/opaque.d.ts)
348
+ - `Branded` - See [`Tagged`](source/opaque.d.ts)
349
+ - `Opaque` - See [`Tagged`](source/opaque.d.ts)
349
350
 
350
351
  ## Tips
351
352
 
@@ -0,0 +1,25 @@
1
+ import type {IsEqual} from './is-equal';
2
+
3
+ /**
4
+ Returns a boolean for whether two given types are both true.
5
+
6
+ Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
7
+
8
+ @example
9
+ ```
10
+ import type {And} from 'type-fest';
11
+
12
+ And<true, true>;
13
+ //=> true
14
+
15
+ And<true, false>;
16
+ //=> false
17
+ ```
18
+
19
+ @see {@link Or}
20
+ */
21
+ export type And<A extends boolean, B extends boolean> = [A, B][number] extends true
22
+ ? true
23
+ : true extends [IsEqual<A, false>, IsEqual<B, false>][number]
24
+ ? false
25
+ : never;
@@ -3,8 +3,9 @@ import type {LessThanOrEqual} from './less-than-or-equal';
3
3
  import type {GreaterThanOrEqual} from './greater-than-or-equal';
4
4
  import type {GreaterThan} from './greater-than';
5
5
  import type {IsNegative} from './numeric';
6
- import type {And, Not, ArrayMin} from './internal';
6
+ import type {Not, ArrayMin} from './internal';
7
7
  import type {IsEqual} from './is-equal';
8
+ import type {And} from './and';
8
9
  import type {ArraySplice} from './array-splice';
9
10
 
10
11
  /**
@@ -1,6 +1,8 @@
1
- import type {NumberAbsolute, And, Or, PositiveNumericStringGt} from './internal';
1
+ import type {NumberAbsolute, PositiveNumericStringGt} from './internal';
2
2
  import type {IsEqual} from './is-equal';
3
3
  import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric';
4
+ import type {And} from './and';
5
+ import type {Or} from './or';
4
6
 
5
7
  /**
6
8
  Returns a boolean for whether a given number is greater than another number.
@@ -451,42 +451,6 @@ IsPrimitive<Object>
451
451
  */
452
452
  export type IsPrimitive<T> = [T] extends [Primitive] ? true : false;
453
453
 
454
- /**
455
- Returns a boolean for whether A and B are both true.
456
-
457
- @example
458
- ```
459
- And<true, true>;
460
- //=> true
461
-
462
- And<true, false>;
463
- //=> false
464
- ```
465
- */
466
- export type And<A extends boolean, B extends boolean> = [A, B][number] extends true
467
- ? true
468
- : true extends [IsEqual<A, false>, IsEqual<B, false>][number]
469
- ? false
470
- : never;
471
-
472
- /**
473
- Returns a boolean for either A or B is true.
474
-
475
- @example
476
- ```
477
- Or<true, false>;
478
- //=> true
479
-
480
- Or<false, false>;
481
- //=> false
482
- ```
483
- */
484
- export type Or<A extends boolean, B extends boolean> = [A, B][number] extends false
485
- ? false
486
- : true extends [IsEqual<A, true>, IsEqual<B, true>][number]
487
- ? true
488
- : never;
489
-
490
454
  /**
491
455
  Returns a boolean for whether A is false.
492
456
 
@@ -9,14 +9,7 @@ Useful in type utilities, such as checking if something does not occur.
9
9
 
10
10
  @example
11
11
  ```
12
- import type {IsNever} from 'type-fest';
13
-
14
- type And<A, B> =
15
- A extends true
16
- ? B extends true
17
- ? true
18
- : false
19
- : false;
12
+ import type {IsNever, And} from 'type-fest';
20
13
 
21
14
  // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
22
15
  type AreStringsEqual<A extends string, B extends string> =
@@ -76,6 +76,7 @@ type Person = {
76
76
  ```
77
77
 
78
78
  @category Type
79
+ @deprecated Use {@link Tagged} instead
79
80
  */
80
81
  export type Opaque<Type, Token = unknown> = Type & TagContainer<Token>;
81
82
 
@@ -109,6 +110,7 @@ type WillWork = UnwrapOpaque<Tagged<number, 'AccountNumber'>>; // number
109
110
  ```
110
111
 
111
112
  @category Type
113
+ @deprecated Use {@link UnwrapTagged} instead
112
114
  */
113
115
  export type UnwrapOpaque<OpaqueType extends TagContainer<unknown>> =
114
116
  OpaqueType extends Tag<PropertyKey, any>
package/source/or.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type {IsEqual} from './is-equal';
2
+
3
+ /**
4
+ Returns a boolean for whether either of two given types are true.
5
+
6
+ Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
7
+
8
+ @example
9
+ ```
10
+ import type {Or} from 'type-fest';
11
+
12
+ Or<true, false>;
13
+ //=> true
14
+
15
+ Or<false, false>;
16
+ //=> false
17
+ ```
18
+
19
+ @see {@link And}
20
+ */
21
+ export type Or<A extends boolean, B extends boolean> = [A, B][number] extends false
22
+ ? false
23
+ : true extends [IsEqual<A, true>, IsEqual<B, true>][number]
24
+ ? true
25
+ : never;
@@ -1,8 +1,10 @@
1
- import type {NumberAbsolute, BuildTuple, And, Or} from './internal';
1
+ import type {NumberAbsolute, BuildTuple} from './internal';
2
2
  import type {IsEqual} from './is-equal';
3
3
  import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric';
4
4
  import type {LessThan} from './less-than';
5
5
  import type {Sum} from './sum';
6
+ import type {And} from './and';
7
+ import type {Or} from './or';
6
8
 
7
9
  /**
8
10
  Returns the difference between two numbers.
package/source/sum.d.ts CHANGED
@@ -1,7 +1,9 @@
1
- import type {NumberAbsolute, BuildTuple, And, Or, ArrayMax, ArrayMin} from './internal';
1
+ import type {NumberAbsolute, BuildTuple, ArrayMax, ArrayMin} from './internal';
2
2
  import type {IsEqual} from './is-equal';
3
3
  import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric';
4
4
  import type {Subtract} from './subtract';
5
+ import type {And} from './and';
6
+ import type {Or} from './or';
5
7
 
6
8
  /**
7
9
  Returns the sum of two numbers.
@@ -19,6 +19,7 @@ declare namespace TsConfigJson {
19
19
  | 'ESNext'
20
20
  | 'Node16'
21
21
  | 'NodeNext'
22
+ | 'Preserve'
22
23
  | 'None'
23
24
  // Lowercase alternatives
24
25
  | 'commonjs'
@@ -32,6 +33,7 @@ declare namespace TsConfigJson {
32
33
  | 'esnext'
33
34
  | 'node16'
34
35
  | 'nodenext'
36
+ | 'preserve'
35
37
  | 'none';
36
38
 
37
39
  export type NewLine =
@@ -113,6 +115,14 @@ declare namespace TsConfigJson {
113
115
  | 'ES2021.Promise'
114
116
  | 'ES2021.String'
115
117
  | 'ES2021.WeakRef'
118
+ | 'ES2022'
119
+ | 'ES2022.Array'
120
+ | 'ES2022.Error'
121
+ | 'ES2022.Intl'
122
+ | 'ES2022.Object'
123
+ | 'ES2022.SharedMemory'
124
+ | 'ES2022.String'
125
+ | 'ES2022.RegExp'
116
126
  | 'ESNext'
117
127
  | 'ESNext.Array'
118
128
  | 'ESNext.AsyncIterable'
@@ -172,6 +182,14 @@ declare namespace TsConfigJson {
172
182
  | 'es2021.promise'
173
183
  | 'es2021.string'
174
184
  | 'es2021.weakref'
185
+ | 'es2022'
186
+ | 'es2022.array'
187
+ | 'es2022.error'
188
+ | 'es2022.intl'
189
+ | 'es2022.object'
190
+ | 'es2022.sharedmemory'
191
+ | 'es2022.string'
192
+ | 'es2022.regexp'
175
193
  | 'esnext'
176
194
  | 'esnext.array'
177
195
  | 'esnext.asynciterable'