Skip to content

Latest commit

 

History

History
49 lines (40 loc) · 1.27 KB

File metadata and controls

49 lines (40 loc) · 1.27 KB

Home > types-kit > And

And type

And operator for types.

Signature:

export type And<A extends readonly unknown[]> = If<
  IsTuple<A>,
  A extends readonly [infer Current, ...infer Rest]
    ? If<
        Current,
        If<
          IsTuple<Rest>,
          And<Rest>,
          Or<[IsEmptyTypeArray<Rest>, IsTruthy<ArrayItem<Rest>>]>
        >,
        false
      >
    : A extends readonly [...infer Rest, infer Current]
    ? If<
        Current,
        If<
          IsTuple<Rest>,
          And<Rest>,
          Or<[IsEmptyTypeArray<Rest>, IsTruthy<ArrayItem<Rest>>]>
        >,
        false
      >
    : never,
  IsTruthy<ArrayItem<A>>
>

References: If, IsTuple, And, Or, IsEmptyTypeArray, IsTruthy, ArrayItem

Example

 // Expect: false
 type Foo = And<[1, 2, false]>
 // Expect: true
 type Bar = And<[true, 1, 'str']>