@depup/type-fest 5.4.4-depup.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/README.md +25 -0
- package/index.d.ts +211 -0
- package/license-cc0 +121 -0
- package/license-mit +9 -0
- package/package.json +85 -0
- package/readme.md +1052 -0
- package/source/all-extend.d.ts +120 -0
- package/source/all-union-fields.d.ts +91 -0
- package/source/and.d.ts +81 -0
- package/source/array-element.d.ts +46 -0
- package/source/array-indices.d.ts +25 -0
- package/source/array-reverse.d.ts +84 -0
- package/source/array-slice.d.ts +132 -0
- package/source/array-splice.d.ts +104 -0
- package/source/array-tail.d.ts +70 -0
- package/source/array-values.d.ts +24 -0
- package/source/arrayable.d.ts +31 -0
- package/source/async-return-type.d.ts +28 -0
- package/source/asyncify.d.ts +25 -0
- package/source/basic.d.ts +38 -0
- package/source/camel-case.d.ts +92 -0
- package/source/camel-cased-properties-deep.d.ts +99 -0
- package/source/camel-cased-properties.d.ts +45 -0
- package/source/characters.d.ts +67 -0
- package/source/conditional-except.d.ts +47 -0
- package/source/conditional-keys.d.ts +63 -0
- package/source/conditional-pick-deep.d.ts +120 -0
- package/source/conditional-pick.d.ts +46 -0
- package/source/conditional-simplify-deep.d.ts +73 -0
- package/source/conditional-simplify.d.ts +50 -0
- package/source/delimiter-case.d.ts +77 -0
- package/source/delimiter-cased-properties-deep.d.ts +108 -0
- package/source/delimiter-cased-properties.d.ts +48 -0
- package/source/distributed-omit.d.ts +96 -0
- package/source/distributed-pick.d.ts +92 -0
- package/source/empty-object.d.ts +51 -0
- package/source/entries.d.ts +64 -0
- package/source/entry.d.ts +67 -0
- package/source/exact.d.ts +73 -0
- package/source/except.d.ts +112 -0
- package/source/exclude-rest-element.d.ts +40 -0
- package/source/exclude-strict.d.ts +51 -0
- package/source/exclusify-union.d.ts +147 -0
- package/source/extends-strict.d.ts +44 -0
- package/source/extract-rest-element.d.ts +30 -0
- package/source/extract-strict.d.ts +51 -0
- package/source/find-global-type.d.ts +68 -0
- package/source/fixed-length-array.d.ts +97 -0
- package/source/get.d.ts +227 -0
- package/source/global-this.d.ts +24 -0
- package/source/globals/index.d.ts +3 -0
- package/source/globals/observable-like.d.ts +78 -0
- package/source/greater-than-or-equal.d.ts +30 -0
- package/source/greater-than.d.ts +58 -0
- package/source/has-optional-keys.d.ts +23 -0
- package/source/has-readonly-keys.d.ts +23 -0
- package/source/has-required-keys.d.ts +61 -0
- package/source/has-writable-keys.d.ts +23 -0
- package/source/if-any.d.ts +28 -0
- package/source/if-empty-object.d.ts +30 -0
- package/source/if-never.d.ts +28 -0
- package/source/if-null.d.ts +28 -0
- package/source/if-unknown.d.ts +28 -0
- package/source/if.d.ts +102 -0
- package/source/includes.d.ts +24 -0
- package/source/int-closed-range.d.ts +47 -0
- package/source/int-range.d.ts +69 -0
- package/source/internal/array.d.ts +151 -0
- package/source/internal/characters.d.ts +65 -0
- package/source/internal/enforce-optional.d.ts +49 -0
- package/source/internal/index.d.ts +11 -0
- package/source/internal/keys.d.ts +100 -0
- package/source/internal/numeric.d.ts +151 -0
- package/source/internal/object.d.ts +292 -0
- package/source/internal/string.d.ts +202 -0
- package/source/internal/tuple.d.ts +79 -0
- package/source/internal/type.d.ts +164 -0
- package/source/invariant-of.d.ts +85 -0
- package/source/is-any.d.ts +31 -0
- package/source/is-equal.d.ts +42 -0
- package/source/is-float.d.ts +43 -0
- package/source/is-integer.d.ts +60 -0
- package/source/is-literal.d.ts +315 -0
- package/source/is-lowercase.d.ts +38 -0
- package/source/is-never.d.ts +56 -0
- package/source/is-null.d.ts +22 -0
- package/source/is-nullable.d.ts +30 -0
- package/source/is-optional-key-of.d.ts +51 -0
- package/source/is-optional.d.ts +28 -0
- package/source/is-readonly-key-of.d.ts +55 -0
- package/source/is-required-key-of.d.ts +51 -0
- package/source/is-tuple.d.ts +92 -0
- package/source/is-undefined.d.ts +22 -0
- package/source/is-union.d.ts +40 -0
- package/source/is-unknown.d.ts +43 -0
- package/source/is-uppercase.d.ts +38 -0
- package/source/is-writable-key-of.d.ts +51 -0
- package/source/iterable-element.d.ts +66 -0
- package/source/join.d.ts +79 -0
- package/source/json-value.d.ts +33 -0
- package/source/jsonifiable.d.ts +37 -0
- package/source/jsonify.d.ts +127 -0
- package/source/kebab-case.d.ts +46 -0
- package/source/kebab-cased-properties-deep.d.ts +65 -0
- package/source/kebab-cased-properties.d.ts +42 -0
- package/source/key-as-string.d.ts +27 -0
- package/source/keys-of-union.d.ts +44 -0
- package/source/last-array-element.d.ts +36 -0
- package/source/less-than-or-equal.d.ts +24 -0
- package/source/less-than.d.ts +28 -0
- package/source/literal-to-primitive-deep.d.ts +71 -0
- package/source/literal-to-primitive.d.ts +38 -0
- package/source/literal-union.d.ts +39 -0
- package/source/merge-deep.d.ts +495 -0
- package/source/merge-exclusive.d.ts +45 -0
- package/source/merge.d.ts +62 -0
- package/source/multidimensional-array.d.ts +38 -0
- package/source/multidimensional-readonly-array.d.ts +38 -0
- package/source/non-empty-object.d.ts +38 -0
- package/source/non-empty-string.d.ts +32 -0
- package/source/non-empty-tuple.d.ts +24 -0
- package/source/numeric.d.ts +226 -0
- package/source/object-merge.d.ts +194 -0
- package/source/omit-deep.d.ts +154 -0
- package/source/omit-index-signature.d.ts +98 -0
- package/source/opaque.d.ts +3 -0
- package/source/optional-keys-of.d.ts +46 -0
- package/source/or.d.ts +89 -0
- package/source/override-properties.d.ts +43 -0
- package/source/package-json.d.ts +710 -0
- package/source/partial-deep.d.ts +155 -0
- package/source/partial-on-undefined-deep.d.ts +81 -0
- package/source/pascal-case.d.ts +51 -0
- package/source/pascal-cased-properties-deep.d.ts +72 -0
- package/source/pascal-cased-properties.d.ts +42 -0
- package/source/paths.d.ts +241 -0
- package/source/pick-deep.d.ts +152 -0
- package/source/pick-index-signature.d.ts +52 -0
- package/source/primitive.d.ts +15 -0
- package/source/promisable.d.ts +27 -0
- package/source/readonly-deep.d.ts +116 -0
- package/source/readonly-keys-of.d.ts +38 -0
- package/source/readonly-tuple.d.ts +34 -0
- package/source/remove-prefix.d.ts +132 -0
- package/source/replace.d.ts +87 -0
- package/source/require-all-or-none.d.ts +54 -0
- package/source/require-at-least-one.d.ts +50 -0
- package/source/require-exactly-one.d.ts +48 -0
- package/source/require-one-or-none.d.ts +49 -0
- package/source/required-deep.d.ts +76 -0
- package/source/required-keys-of.d.ts +38 -0
- package/source/schema.d.ts +119 -0
- package/source/screaming-snake-case.d.ts +30 -0
- package/source/set-field-type.d.ts +67 -0
- package/source/set-non-nullable-deep.d.ts +85 -0
- package/source/set-non-nullable.d.ts +41 -0
- package/source/set-optional.d.ts +46 -0
- package/source/set-parameter-type.d.ts +125 -0
- package/source/set-readonly.d.ts +44 -0
- package/source/set-required-deep.d.ts +64 -0
- package/source/set-required.d.ts +79 -0
- package/source/set-return-type.d.ts +31 -0
- package/source/shared-union-fields-deep.d.ts +180 -0
- package/source/shared-union-fields.d.ts +79 -0
- package/source/simplify-deep.d.ts +117 -0
- package/source/simplify.d.ts +61 -0
- package/source/single-key-object.d.ts +28 -0
- package/source/snake-case.d.ts +47 -0
- package/source/snake-cased-properties-deep.d.ts +65 -0
- package/source/snake-cased-properties.d.ts +42 -0
- package/source/split-on-rest-element.d.ts +106 -0
- package/source/split.d.ts +90 -0
- package/source/spread.d.ts +82 -0
- package/source/string-repeat.d.ts +49 -0
- package/source/string-slice.d.ts +39 -0
- package/source/stringified.d.ts +25 -0
- package/source/structured-cloneable.d.ts +89 -0
- package/source/subtract.d.ts +86 -0
- package/source/sum.d.ts +81 -0
- package/source/tagged-union.d.ts +53 -0
- package/source/tagged.d.ts +263 -0
- package/source/trim.d.ts +29 -0
- package/source/tsconfig-json.d.ts +1324 -0
- package/source/tuple-of.d.ts +80 -0
- package/source/tuple-to-object.d.ts +47 -0
- package/source/tuple-to-union.d.ts +54 -0
- package/source/typed-array.d.ts +19 -0
- package/source/undefined-on-partial-deep.d.ts +83 -0
- package/source/union-to-intersection.d.ts +35 -0
- package/source/union-to-tuple.d.ts +58 -0
- package/source/unknown-array.d.ts +27 -0
- package/source/unknown-map.d.ts +26 -0
- package/source/unknown-record.d.ts +33 -0
- package/source/unknown-set.d.ts +26 -0
- package/source/unwrap-partial.d.ts +33 -0
- package/source/value-of.d.ts +24 -0
- package/source/words.d.ts +122 -0
- package/source/writable-deep.d.ts +84 -0
- package/source/writable-keys-of.d.ts +34 -0
- package/source/writable.d.ts +72 -0
- package/source/xor.d.ts +83 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type {BuiltIns, HasMultipleCallSignatures} from './internal/index.d.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Create a deeply mutable version of an `object`/`ReadonlyMap`/`ReadonlySet`/`ReadonlyArray` type. The inverse of `ReadonlyDeep<T>`. Use `Writable<T>` if you only need one level deep.
|
|
5
|
+
|
|
6
|
+
This can be used to [store and mutate options within a class](https://github.com/sindresorhus/pageres/blob/4a5d05fca19a5fbd2f53842cbf3eb7b1b63bddd2/source/index.ts#L72), [edit `readonly` objects within tests](https://stackoverflow.com/questions/50703834), [construct a `readonly` object within a function](https://github.com/Microsoft/TypeScript/issues/24509), or to define a single model where the only thing that changes is whether or not some of the keys are writable.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {WritableDeep} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type Foo = {
|
|
13
|
+
readonly a: number;
|
|
14
|
+
readonly b: readonly string[]; // To show that mutability is deeply affected.
|
|
15
|
+
readonly c: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const writableDeepFoo: WritableDeep<Foo> = {a: 1, b: ['2'], c: true};
|
|
19
|
+
writableDeepFoo.a = 3;
|
|
20
|
+
writableDeepFoo.b[0] = 'new value';
|
|
21
|
+
writableDeepFoo.b = ['something'];
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Note that types containing overloaded functions are not made deeply writable due to a [TypeScript limitation](https://github.com/microsoft/TypeScript/issues/29732).
|
|
25
|
+
|
|
26
|
+
@see {@link Writable}
|
|
27
|
+
@category Object
|
|
28
|
+
@category Array
|
|
29
|
+
@category Set
|
|
30
|
+
@category Map
|
|
31
|
+
*/
|
|
32
|
+
export type WritableDeep<T> = T extends BuiltIns
|
|
33
|
+
? T
|
|
34
|
+
: T extends (...arguments_: any[]) => unknown
|
|
35
|
+
? {} extends _WritableObjectDeep<T>
|
|
36
|
+
? T
|
|
37
|
+
: HasMultipleCallSignatures<T> extends true
|
|
38
|
+
? T
|
|
39
|
+
: ((...arguments_: Parameters<T>) => ReturnType<T>) & _WritableObjectDeep<T>
|
|
40
|
+
: T extends ReadonlyMap<unknown, unknown>
|
|
41
|
+
? WritableMapDeep<T>
|
|
42
|
+
: T extends ReadonlySet<unknown>
|
|
43
|
+
? WritableSetDeep<T>
|
|
44
|
+
: T extends readonly unknown[]
|
|
45
|
+
? WritableArrayDeep<T>
|
|
46
|
+
: T extends object
|
|
47
|
+
? _WritableObjectDeep<T>
|
|
48
|
+
: unknown;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
Same as `WritableDeep`, but accepts only `Map`s as inputs. Internal helper for `WritableDeep`.
|
|
52
|
+
*/
|
|
53
|
+
type WritableMapDeep<MapType extends ReadonlyMap<unknown, unknown>> =
|
|
54
|
+
MapType extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
55
|
+
? Map<WritableDeep<KeyType>, WritableDeep<ValueType>>
|
|
56
|
+
: MapType; // Should not heppen
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
Same as `WritableDeep`, but accepts only `Set`s as inputs. Internal helper for `WritableDeep`.
|
|
60
|
+
*/
|
|
61
|
+
type WritableSetDeep<SetType extends ReadonlySet<unknown>> =
|
|
62
|
+
SetType extends ReadonlySet<infer ItemType>
|
|
63
|
+
? Set<WritableDeep<ItemType>>
|
|
64
|
+
: SetType; // Should not heppen
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
Same as `WritableDeep`, but accepts only `object`s as inputs. Internal helper for `WritableDeep`.
|
|
68
|
+
*/
|
|
69
|
+
export type _WritableObjectDeep<ObjectType extends object> = {
|
|
70
|
+
-readonly [KeyType in keyof ObjectType]: WritableDeep<ObjectType[KeyType]>
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
Same as `WritableDeep`, but accepts only `Array`s as inputs. Internal helper for `WritableDeep`.
|
|
75
|
+
*/
|
|
76
|
+
type WritableArrayDeep<ArrayType extends readonly unknown[]> =
|
|
77
|
+
ArrayType extends readonly [] ? []
|
|
78
|
+
: ArrayType extends readonly [...infer U, infer V] ? [...WritableArrayDeep<U>, WritableDeep<V>]
|
|
79
|
+
: ArrayType extends readonly [infer U, ...infer V] ? [WritableDeep<U>, ...WritableArrayDeep<V>]
|
|
80
|
+
: ArrayType extends ReadonlyArray<infer U> ? Array<WritableDeep<U>>
|
|
81
|
+
: ArrayType extends Array<infer U> ? Array<WritableDeep<U>>
|
|
82
|
+
: ArrayType;
|
|
83
|
+
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type {ReadonlyKeysOf} from './readonly-keys-of.d.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Extract all writable keys from the given type.
|
|
5
|
+
|
|
6
|
+
This is useful when you want to create a new type that contains writable keys only.
|
|
7
|
+
|
|
8
|
+
@example
|
|
9
|
+
```
|
|
10
|
+
import type {WritableKeysOf} from 'type-fest';
|
|
11
|
+
|
|
12
|
+
type User = {
|
|
13
|
+
name: string;
|
|
14
|
+
surname: string;
|
|
15
|
+
|
|
16
|
+
readonly id: number;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type UpdateRequest<Entity extends object> = Pick<Entity, WritableKeysOf<Entity>>;
|
|
20
|
+
|
|
21
|
+
const update1: UpdateRequest<User> = {
|
|
22
|
+
name: 'Alice',
|
|
23
|
+
surname: 'Acme',
|
|
24
|
+
};
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
@category Utilities
|
|
28
|
+
*/
|
|
29
|
+
export type WritableKeysOf<Type extends object> =
|
|
30
|
+
Type extends unknown // For distributing `Type`
|
|
31
|
+
? Exclude<keyof Type, ReadonlyKeysOf<Type>>
|
|
32
|
+
: never; // Should never happen
|
|
33
|
+
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type {Except} from './except.d.ts';
|
|
2
|
+
import type {Simplify} from './simplify.d.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Create a writable version of the given array type.
|
|
6
|
+
*/
|
|
7
|
+
type WritableArray<ArrayType extends readonly unknown[]> =
|
|
8
|
+
ArrayType extends readonly [] ? []
|
|
9
|
+
: ArrayType extends readonly [...infer U, infer V] ? [...U, V]
|
|
10
|
+
: ArrayType extends readonly [infer U, ...infer V] ? [U, ...V]
|
|
11
|
+
: ArrayType extends ReadonlyArray<infer U> ? U[]
|
|
12
|
+
: ArrayType;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
Create a type that strips `readonly` from the given type. Inverse of `Readonly<T>`.
|
|
16
|
+
|
|
17
|
+
The 2nd argument will be ignored if the input type is not an object.
|
|
18
|
+
|
|
19
|
+
Note: This type can make readonly `Set` and `Map` writable. This behavior is different from `Readonly<T>` (as of TypeScript 5.2.2). See: https://github.com/microsoft/TypeScript/issues/29655
|
|
20
|
+
|
|
21
|
+
This can be used to [store and mutate options within a class](https://github.com/sindresorhus/pageres/blob/4a5d05fca19a5fbd2f53842cbf3eb7b1b63bddd2/source/index.ts#L72), [edit `readonly` objects within tests](https://stackoverflow.com/questions/50703834), [construct a `readonly` object within a function](https://github.com/Microsoft/TypeScript/issues/24509), or to define a single model where the only thing that changes is whether or not some of the keys are writable.
|
|
22
|
+
|
|
23
|
+
@example
|
|
24
|
+
```
|
|
25
|
+
import type {Writable} from 'type-fest';
|
|
26
|
+
|
|
27
|
+
type Foo = {
|
|
28
|
+
readonly a: number;
|
|
29
|
+
readonly b: readonly string[]; // To show that only the mutability status of the properties, not their values, are affected.
|
|
30
|
+
readonly c: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const writableFoo: Writable<Foo> = {a: 1, b: ['2'], c: true};
|
|
34
|
+
writableFoo.a = 3;
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
writableFoo.b[0] = 'new value'; // Will still fail as the value of property "b" is still a readonly type.
|
|
37
|
+
writableFoo.b = ['something']; // Will work as the "b" property itself is no longer readonly.
|
|
38
|
+
|
|
39
|
+
type SomeWritable = Writable<Foo, 'b' | 'c'>;
|
|
40
|
+
// type SomeWritable = {
|
|
41
|
+
// readonly a: number;
|
|
42
|
+
// b: readonly string[]; // It's now writable. The type of the property remains unaffected.
|
|
43
|
+
// c: boolean; // It's now writable.
|
|
44
|
+
// }
|
|
45
|
+
|
|
46
|
+
// Also supports array
|
|
47
|
+
const readonlyArray: readonly number[] = [1, 2, 3];
|
|
48
|
+
// @ts-expect-error
|
|
49
|
+
readonlyArray.push(4); // Will fail as the array itself is readonly.
|
|
50
|
+
const writableArray: Writable<typeof readonlyArray> = readonlyArray as Writable<typeof readonlyArray>;
|
|
51
|
+
writableArray.push(4); // Will work as the array itself is now writable.
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
@category Object
|
|
55
|
+
*/
|
|
56
|
+
export type Writable<BaseType, Keys extends keyof BaseType = keyof BaseType> =
|
|
57
|
+
BaseType extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
58
|
+
? Map<KeyType, ValueType>
|
|
59
|
+
: BaseType extends ReadonlySet<infer ItemType>
|
|
60
|
+
? Set<ItemType>
|
|
61
|
+
: BaseType extends readonly unknown[]
|
|
62
|
+
// Handle array
|
|
63
|
+
? WritableArray<BaseType>
|
|
64
|
+
// Handle object
|
|
65
|
+
: Simplify<
|
|
66
|
+
// Pick just the keys that are not writable from the base type.
|
|
67
|
+
Except<BaseType, Keys> &
|
|
68
|
+
// Pick the keys that should be writable from the base type and make them writable by removing the `readonly` modifier from the key.
|
|
69
|
+
{-readonly [KeyType in keyof Pick<BaseType, Keys>]: Pick<BaseType, Keys>[KeyType]}
|
|
70
|
+
>;
|
|
71
|
+
|
|
72
|
+
export {};
|
package/source/xor.d.ts
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type {Not} from './internal/type.d.ts';
|
|
2
|
+
import type {And} from './and.d.ts';
|
|
3
|
+
import type {Or} from './or.d.ts';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
Returns a boolean for whether only one of two given types is true.
|
|
7
|
+
|
|
8
|
+
Use-case: Constructing complex conditional types where one single condition must be satisfied.
|
|
9
|
+
|
|
10
|
+
@example
|
|
11
|
+
```
|
|
12
|
+
import type {Xor} from 'type-fest';
|
|
13
|
+
|
|
14
|
+
type TT = Xor<true, true>;
|
|
15
|
+
//=> false
|
|
16
|
+
|
|
17
|
+
type TF = Xor<true, false>;
|
|
18
|
+
//=> true
|
|
19
|
+
|
|
20
|
+
type FT = Xor<false, true>;
|
|
21
|
+
//=> true
|
|
22
|
+
|
|
23
|
+
type FF = Xor<false, false>;
|
|
24
|
+
//=> false
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
|
|
28
|
+
For example, `Xor<false, boolean>` expands to `Xor<false, true> | Xor<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
|
|
29
|
+
|
|
30
|
+
@example
|
|
31
|
+
```
|
|
32
|
+
import type {Xor} from 'type-fest';
|
|
33
|
+
|
|
34
|
+
type A = Xor<false, boolean>;
|
|
35
|
+
//=> boolean
|
|
36
|
+
|
|
37
|
+
type B = Xor<boolean, false>;
|
|
38
|
+
//=> boolean
|
|
39
|
+
|
|
40
|
+
type C = Xor<true, boolean>;
|
|
41
|
+
//=> boolean
|
|
42
|
+
|
|
43
|
+
type D = Xor<boolean, true>;
|
|
44
|
+
//=> boolean
|
|
45
|
+
|
|
46
|
+
type E = Xor<boolean, boolean>;
|
|
47
|
+
//=> boolean
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
|
|
51
|
+
|
|
52
|
+
@example
|
|
53
|
+
```
|
|
54
|
+
import type {Xor} from 'type-fest';
|
|
55
|
+
|
|
56
|
+
type A = Xor<true, never>;
|
|
57
|
+
//=> true
|
|
58
|
+
|
|
59
|
+
type B = Xor<never, true>;
|
|
60
|
+
//=> true
|
|
61
|
+
|
|
62
|
+
type C = Xor<false, never>;
|
|
63
|
+
//=> false
|
|
64
|
+
|
|
65
|
+
type D = Xor<never, false>;
|
|
66
|
+
//=> false
|
|
67
|
+
|
|
68
|
+
type E = Xor<boolean, never>;
|
|
69
|
+
//=> boolean
|
|
70
|
+
|
|
71
|
+
type F = Xor<never, boolean>;
|
|
72
|
+
//=> boolean
|
|
73
|
+
|
|
74
|
+
type G = Xor<never, never>;
|
|
75
|
+
//=> false
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
@see {@link And}
|
|
79
|
+
@see {@link Or}
|
|
80
|
+
*/
|
|
81
|
+
export type Xor<A extends boolean, B extends boolean> = And<Or<A, B>, Not<And<A, B>>>;
|
|
82
|
+
|
|
83
|
+
export {};
|