Type alias ArrayIncludes<Arr, P>

ArrayIncludes<Arr, P>: Arr extends [infer S, ...(infer E)]
    ? Equals<S, P> extends true
        ? true
        : ArrayIncludes<E, P>
    : false

Checks if a given type is in an array type

Type Parameters

  • Arr
  • P

Example

ArrayIncludes<[bigint, true, 2, 3, 5, 6, 'seven'], true> // Result: true

type T = NewType<'T',string >;
ArrayIncludes<[T, 2, 3, 5, 6, 7], string>; // Result: false
ArrayIncludes<[string, 2, 3, 5, 6, 7], string>; // Result: true

Returns

true if found, else false