Type alias HeadAndTail<Input>

HeadAndTail<Input>: Input extends readonly [head: infer HeadItem, tail: infer TailItems]
    ? readonly [head: HeadItem, tail: TailItems]
    : Input extends `${infer FirstCharacter}${infer RestOfString}`
        ? readonly [head: FirstCharacter, tail: RestOfString]
        : Input extends EmptyArray | EmptyString
            ? readonly [head: undefined, tail: Input]
            : readonly [head: Maybe<Input[number]>, tail: Input]

Get a couple with the head and tail types of an ArrayLike.


Given a type argument (an ArrayLike), this returns a couple with the type of the item in index 0 first, and the rest of the ArrayLike after.


const array = ["🟢", "🟩", "💚"];
const headAndTail: HeadAndTail<typeof array> = ["🟢", ["🟩", "💚"]];


Type Parameters