forked from sindresorhus/type-fest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathor.d.ts
More file actions
89 lines (63 loc) · 1.7 KB
/
Copy pathor.d.ts
File metadata and controls
89 lines (63 loc) · 1.7 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
84
85
86
87
88
89
import type {If} from './if.d.ts';
import type {IsNever} from './is-never.d.ts';
/**
Returns a boolean for whether either of two given types is true.
Use-case: Constructing complex conditional types where at least one condition must be satisfied.
@example
```
import type {Or} from 'type-fest';
type TT = Or<true, true>;
//=> true
type TF = Or<true, false>;
//=> true
type FT = Or<false, true>;
//=> true
type FF = Or<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, `Or<false, boolean>` expands to `Or<false, true> | Or<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
@example
```
import type {Or} from 'type-fest';
type A = Or<false, boolean>;
//=> boolean
type B = Or<boolean, false>;
//=> boolean
type C = Or<true, boolean>;
//=> true
type D = Or<boolean, true>;
//=> true
type E = Or<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 {Or} from 'type-fest';
type A = Or<true, never>;
//=> true
type B = Or<never, true>;
//=> true
type C = Or<false, never>;
//=> false
type D = Or<never, false>;
//=> false
type E = Or<boolean, never>;
//=> boolean
type F = Or<never, boolean>;
//=> boolean
type G = Or<never, never>;
//=> false
```
@see {@link And}
@see {@link Xor}
*/
export type Or<A extends boolean, B extends boolean> =
_Or<If<IsNever<A>, false, A>, If<IsNever<B>, false, B>>; // `never` is treated as `false`
export type _Or<A extends boolean, B extends boolean> = A extends true
? true
: B extends true
? true
: false;
export {};