-
-
Notifications
You must be signed in to change notification settings - Fork 677
Expand file tree
/
Copy pathxor.d.ts
More file actions
83 lines (58 loc) · 1.59 KB
/
xor.d.ts
File metadata and controls
83 lines (58 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import type {Not} from './internal/type.d.ts';
import type {And} from './and.d.ts';
import type {Or} from './or.d.ts';
/**
Returns a boolean for whether only one of two given types is true.
Use-case: Constructing complex conditional types where one single condition must be satisfied.
@example
```
import type {Xor} from 'type-fest';
type TT = Xor<true, true>;
//=> false
type TF = Xor<true, false>;
//=> true
type FT = Xor<false, true>;
//=> true
type FF = Xor<false, false>;
//=> false
```
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
For example, `Xor<false, boolean>` expands to `Xor<false, true> | Xor<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
@example
```
import type {Xor} from 'type-fest';
type A = Xor<false, boolean>;
//=> boolean
type B = Xor<boolean, false>;
//=> boolean
type C = Xor<true, boolean>;
//=> boolean
type D = Xor<boolean, true>;
//=> boolean
type E = Xor<boolean, boolean>;
//=> boolean
```
Note: If `never` is passed as an argument, it is treated as `false` and the result is computed accordingly.
@example
```
import type {Xor} from 'type-fest';
type A = Xor<true, never>;
//=> true
type B = Xor<never, true>;
//=> true
type C = Xor<false, never>;
//=> false
type D = Xor<never, false>;
//=> false
type E = Xor<boolean, never>;
//=> boolean
type F = Xor<never, boolean>;
//=> boolean
type G = Xor<never, never>;
//=> false
```
@see {@link And}
@see {@link Or}
*/
export type Xor<A extends boolean, B extends boolean> = And<Or<A, B>, Not<And<A, B>>>;
export {};