Type alias ArrayUnique<T, R>

ArrayUnique<T, R>: T extends [infer S, ...(infer E)]
    ? ArrayIncludes<R, S> extends true
        ? ArrayUnique<E, R>
        : ArrayUnique<E, [...R, S]>
    : R

A type that constructs a new array containing only unique elements from a given array type.

Type Parameters

  • T

    The input array type from which unique elements are extracted.

  • R extends unknown[] = []

Example

 type UArr = UniqueArray<
[unknown, unknown, 'foo', any, never, never, '33', 33, '33']
>; // => [unknown, 'foo', any, never, '33', 33]