-
-
Notifications
You must be signed in to change notification settings - Fork 675
Expand file tree
/
Copy pathand.d.ts
More file actions
81 lines (56 loc) · 1.47 KB
/
and.d.ts
File metadata and controls
81 lines (56 loc) · 1.47 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
import type {AllExtend} from './all-extend.d.ts';
/**
Returns a boolean for whether two given types are both true.
Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
@example
```
import type {And} from 'type-fest';
type TT = And<true, true>;
//=> true
type TF = And<true, false>;
//=> false
type FT = And<false, true>;
//=> false
type FF = And<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, `And<true, boolean>` expands to `And<true, true> | And<true, false>`, which simplifies to `true | false` (i.e., `boolean`).
@example
```
import type {And} from 'type-fest';
type A = And<true, boolean>;
//=> boolean
type B = And<boolean, true>;
//=> boolean
type C = And<false, boolean>;
//=> false
type D = And<boolean, false>;
//=> false
type E = And<boolean, boolean>;
//=> boolean
```
Note: If either of the types is `never`, the result becomes `false`.
@example
```
import type {And} from 'type-fest';
type A = And<true, never>;
//=> false
type B = And<never, true>;
//=> false
type C = And<false, never>;
//=> false
type D = And<never, false>;
//=> false
type E = And<boolean, never>;
//=> false
type F = And<never, boolean>;
//=> false
type G = And<never, never>;
//=> false
```
@see {@link Or}
@see {@link Xor}
*/
export type And<A extends boolean, B extends boolean> = AllExtend<[A, B], true>;
export {};