diff --git a/readme.md b/readme.md index 5c6bfd8f2..d4cb19127 100644 --- a/readme.md +++ b/readme.md @@ -199,6 +199,7 @@ Click the type names for complete docs. - [`DistributedOmit`](source/distributed-omit.d.ts) - Omits keys from a type, distributing the operation over a union. - [`DistributedPick`](source/distributed-pick.d.ts) - Picks keys from a type, distributing the operation over a union. - [`And`](source/and.d.ts) - Returns a boolean for whether two given types are both true. +- [`Or`](source/or.d.ts) - Returns a boolean for whether either of two given types are true. ### Type Guard diff --git a/source/and.d.ts b/source/and.d.ts index ed6c14f4d..3f9659fd6 100644 --- a/source/and.d.ts +++ b/source/and.d.ts @@ -15,6 +15,8 @@ And; And; //=> false ``` + +@see {@link Or} */ export type And = [A, B][number] extends true ? true diff --git a/source/greater-than.d.ts b/source/greater-than.d.ts index f749bd6bd..37f04be53 100644 --- a/source/greater-than.d.ts +++ b/source/greater-than.d.ts @@ -1,7 +1,8 @@ -import type {NumberAbsolute, Or, PositiveNumericStringGt} from './internal'; +import type {NumberAbsolute, PositiveNumericStringGt} from './internal'; import type {IsEqual} from './is-equal'; import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric'; import type {And} from './and'; +import type {Or} from './or'; /** Returns a boolean for whether a given number is greater than another number. diff --git a/source/internal.d.ts b/source/internal.d.ts index 9d2e29fe1..f98dfa7a5 100644 --- a/source/internal.d.ts +++ b/source/internal.d.ts @@ -451,24 +451,6 @@ IsPrimitive */ export type IsPrimitive = [T] extends [Primitive] ? true : false; -/** -Returns a boolean for either A or B is true. - -@example -``` -Or; -//=> true - -Or; -//=> false -``` -*/ -export type Or = [A, B][number] extends false - ? false - : true extends [IsEqual, IsEqual][number] - ? true - : never; - /** Returns a boolean for whether A is false. diff --git a/source/or.d.ts b/source/or.d.ts new file mode 100644 index 000000000..2794ed80e --- /dev/null +++ b/source/or.d.ts @@ -0,0 +1,25 @@ +import type {IsEqual} from './is-equal'; + +/** +Returns a boolean for whether either of two given types are true. + +Use-case: Constructing complex conditional types where multiple conditions must be satisfied. + +@example +``` +import type {Or} from 'type-fest'; + +Or; +//=> true + +Or; +//=> false +``` + +@see {@link And} +*/ +export type Or = [A, B][number] extends false + ? false + : true extends [IsEqual, IsEqual][number] + ? true + : never; diff --git a/source/subtract.d.ts b/source/subtract.d.ts index 51a1537f0..02b0f10fa 100644 --- a/source/subtract.d.ts +++ b/source/subtract.d.ts @@ -1,9 +1,10 @@ -import type {NumberAbsolute, BuildTuple, Or} from './internal'; +import type {NumberAbsolute, BuildTuple} from './internal'; import type {IsEqual} from './is-equal'; import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric'; import type {LessThan} from './less-than'; import type {Sum} from './sum'; import type {And} from './and'; +import type {Or} from './or'; /** Returns the difference between two numbers. diff --git a/source/sum.d.ts b/source/sum.d.ts index 96efbd662..14ecd8f54 100644 --- a/source/sum.d.ts +++ b/source/sum.d.ts @@ -1,8 +1,9 @@ -import type {NumberAbsolute, BuildTuple, Or, ArrayMax, ArrayMin} from './internal'; +import type {NumberAbsolute, BuildTuple, ArrayMax, ArrayMin} from './internal'; import type {IsEqual} from './is-equal'; import type {PositiveInfinity, NegativeInfinity, IsNegative} from './numeric'; import type {Subtract} from './subtract'; import type {And} from './and'; +import type {Or} from './or'; /** Returns the sum of two numbers. diff --git a/test-d/internal/or.ts b/test-d/or.ts similarity index 87% rename from test-d/internal/or.ts rename to test-d/or.ts index 698cf8048..c98f92352 100644 --- a/test-d/internal/or.ts +++ b/test-d/or.ts @@ -1,5 +1,5 @@ import {expectType} from 'tsd'; -import type {Or} from '../../source/internal'; +import type {Or} from '../source/or'; declare const never: never;