-
-
Notifications
You must be signed in to change notification settings - Fork 679
Expand file tree
/
Copy pathand-all.d.ts
More file actions
76 lines (53 loc) · 2 KB
/
and-all.d.ts
File metadata and controls
76 lines (53 loc) · 2 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
import type {AllExtend} from './all-extend.d.ts';
/**
Returns a boolean for whether all of the given elements are `true`.
Use-cases:
- Check if all conditions in a list of booleans are met.
@example
```
import type {AndAll} from 'type-fest';
type TTT = AndAll<[true, true, true]>;
//=> true
type TTF = AndAll<[true, true, false]>;
//=> false
type TFT = AndAll<[true, false, true]>;
//=> false
```
Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
For example, `AndAll<[true, boolean]>` expands to `AndAll<[true, true]> | AndAll<[true, false]>`, which simplifies to `true | false` (i.e., `boolean`).
@example
```
import type {AndAll} from 'type-fest';
type A = AndAll<[true, boolean]>;
//=> boolean
type B = AndAll<[false, boolean]>;
//=> false
```
Note: If any of the elements is `never`, the result becomes `false`.
@example
```
import type {AndAll} from 'type-fest';
type A = AndAll<[true, true, never]>;
//=> false
type B = AndAll<[false, never, never]>;
//=> false
type C = AndAll<[never, never, never]>;
//=> false
type D = AndAll<[boolean, true, never]>;
//=> false
```
Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
@example
```
import type {AndAll} from 'type-fest';
type A = AndAll<[false, any]>;
//=> false
type B = AndAll<[true, any]>;
//=> boolean
```
Note: `AndAll<[]>` evaluates to `true` due to the concept of [vacuous truth](https://en.wikipedia.org/wiki/Logical_conjunction#:~:text=In%20keeping%20with%20the%20concept%20of%20vacuous%20truth%2C%20when%20conjunction%20is%20defined%20as%20an%20operator%20or%20function%20of%20arbitrary%20arity%2C%20the%20empty%20conjunction%20(AND%2Ding%20over%20an%20empty%20set%20of%20operands)%20is%20often%20defined%20as%20having%20the%20result%20true.), i.e., there are no `false` elements in an empty tuple.
@see {@link And}
@see {@link OrAll}
*/
export type AndAll<T extends readonly boolean[]> = AllExtend<T, true>;
export {};