Skip to content

Commit ad62d2c

Browse files
benzariasindresorhussom-sm
authored
Or/And: Fix documentation errors and add link to Xor (#1261)
Co-authored-by: Sindre Sorhus <[email protected]> Co-authored-by: Som Shekhar Mukherjee <[email protected]>
1 parent b2caa3f commit ad62d2c

File tree

5 files changed

+33
-24
lines changed

5 files changed

+33
-24
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ Click the type names for complete docs.
179179
- [`DistributedOmit`](source/distributed-omit.d.ts) - Omits keys from a type, distributing the operation over a union.
180180
- [`DistributedPick`](source/distributed-pick.d.ts) - Picks keys from a type, distributing the operation over a union.
181181
- [`And`](source/and.d.ts) - Returns a boolean for whether two given types are both true.
182-
- [`Or`](source/or.d.ts) - Returns a boolean for whether either of two given types are true.
182+
- [`Or`](source/or.d.ts) - Returns a boolean for whether either of two given types is true.
183183
- [`Xor`](source/xor.d.ts) - Returns a boolean for whether only one of two given types is true.
184184
- [`AllExtend`](source/all-extend.d.ts) - Returns a boolean for whether every element in an array type extends another type.
185185
- [`NonEmptyTuple`](source/non-empty-tuple.d.ts) - Matches any non-empty tuple.

source/and.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type E = And<boolean, boolean>;
4646
```
4747
4848
Note: If either of the types is `never`, the result becomes `false`.
49+
4950
@example
5051
```
5152
import type {And} from 'type-fest';
@@ -73,6 +74,7 @@ type G = And<never, never>;
7374
```
7475
7576
@see {@link Or}
77+
@see {@link Xor}
7678
*/
7779
export type And<A extends boolean, B extends boolean> = AllExtend<[A, B], true>;
7880

source/or.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import type {If} from './if.d.ts';
22
import type {IsNever} from './is-never.d.ts';
33

44
/**
5-
Returns a boolean for whether either of two given types are true.
5+
Returns a boolean for whether either of two given types is true.
66
7-
Use-case: Constructing complex conditional types where multiple conditions must be satisfied.
7+
Use-case: Constructing complex conditional types where at least one condition must be satisfied.
88
99
@example
1010
```
1111
import type {Or} from 'type-fest';
1212
13-
type TT = Or<true, false>;
13+
type TT = Or<true, true>;
1414
//=> true
1515
1616
type TF = Or<true, false>;
@@ -24,10 +24,11 @@ type FF = Or<false, false>;
2424
```
2525
2626
Note: When `boolean` is passed as an argument, it is distributed into separate cases, and the final result is a union of those cases.
27-
For example, `And<false, boolean>` expands to `And<false, true> | And<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
27+
For example, `Or<false, boolean>` expands to `Or<false, true> | Or<false, false>`, which simplifies to `true | false` (i.e., `boolean`).
28+
2829
@example
2930
```
30-
import type {And} from 'type-fest';
31+
import type {Or} from 'type-fest';
3132
3233
type A = Or<false, boolean>;
3334
//=> boolean
@@ -74,6 +75,7 @@ type G = Or<never, never>;
7475
```
7576
7677
@see {@link And}
78+
@see {@link Xor}
7779
*/
7880
export type Or<A extends boolean, B extends boolean> =
7981
_Or<If<IsNever<A>, false, A>, If<IsNever<B>, false, B>>; // `never` is treated as `false`

test-d/and.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
import {expectType} from 'tsd';
22
import type {And} from '../source/and.d.ts';
33

4+
declare const boolean: boolean;
5+
46
expectType<And<true, true>>(true);
57
expectType<And<true, false>>(false);
68
expectType<And<false, true>>(false);
79
expectType<And<false, false>>(false);
810

9-
expectType<And<true, boolean>>({} as boolean);
10-
expectType<And<boolean, true>>({} as boolean);
11+
expectType<And<true, boolean>>(boolean);
12+
expectType<And<boolean, true>>(boolean);
1113
expectType<And<false, boolean>>(false);
1214
expectType<And<boolean, false>>(false);
13-
expectType<And<boolean, boolean>>({} as boolean);
15+
expectType<And<boolean, boolean>>(boolean);
1416

1517
// Boundary cases
16-
expectType<And<any, true>>({} as boolean);
17-
expectType<And<true, any>>({} as boolean);
18+
expectType<And<any, true>>(boolean);
19+
expectType<And<true, any>>(boolean);
1820
expectType<And<any, false>>(false);
1921
expectType<And<false, any>>(false);
20-
expectType<And<any, boolean>>({} as boolean);
21-
expectType<And<boolean, any>>({} as boolean);
22-
expectType<And<any, any>>({} as boolean);
22+
expectType<And<any, boolean>>(boolean);
23+
expectType<And<boolean, any>>(boolean);
24+
expectType<And<any, any>>(boolean);
2325

2426
expectType<And<never, true>>(false);
2527
expectType<And<true, never>>(false);

test-d/or.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
11
import {expectType} from 'tsd';
22
import type {Or} from '../source/or.d.ts';
33

4+
declare const boolean: boolean;
5+
46
expectType<Or<true, true>>(true);
57
expectType<Or<true, false>>(true);
68
expectType<Or<false, true>>(true);
79
expectType<Or<false, false>>(false);
810

911
expectType<Or<true, boolean>>(true);
1012
expectType<Or<boolean, true>>(true);
11-
expectType<Or<false, boolean>>({} as boolean);
12-
expectType<Or<boolean, false>>({} as boolean);
13-
expectType<Or<boolean, boolean>>({} as boolean);
13+
expectType<Or<false, boolean>>(boolean);
14+
expectType<Or<boolean, false>>(boolean);
15+
expectType<Or<boolean, boolean>>(boolean);
1416

17+
// Boundary cases
1518
expectType<Or<true, any>>(true);
1619
expectType<Or<any, true>>(true);
17-
expectType<Or<false, any>>({} as boolean);
18-
expectType<Or<any, false>>({} as boolean);
19-
expectType<Or<boolean, any>>({} as boolean);
20-
expectType<Or<any, boolean>>({} as boolean);
21-
expectType<Or<any, any>>({} as boolean);
20+
expectType<Or<false, any>>(boolean);
21+
expectType<Or<any, false>>(boolean);
22+
expectType<Or<boolean, any>>(boolean);
23+
expectType<Or<any, boolean>>(boolean);
24+
expectType<Or<any, any>>(boolean);
2225

2326
expectType<Or<true, never>>(true);
2427
expectType<Or<never, true>>(true);
2528
expectType<Or<false, never>>(false);
2629
expectType<Or<never, false>>(false);
27-
expectType<Or<boolean, never>>({} as boolean);
28-
expectType<Or<never, boolean>>({} as boolean);
30+
expectType<Or<boolean, never>>(boolean);
31+
expectType<Or<never, boolean>>(boolean);
2932
expectType<Or<never, never>>(false);

0 commit comments

Comments
 (0)