Type alias HeadAndTail<Input>

HeadAndTail<Input>: Input extends readonly [infer Head, ...(infer Tail)] ? readonly [Head, Tail] : Input extends `${infer Head}${infer Tail}` ? readonly [Head, Tail] : Input extends EmptyArray | EmptyString ? readonly [undefined, Input] : readonly [Input[number] | undefined, Input]

Get a couple with the head and tail of an array or string.

Example

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

Type Parameters

  • Input extends ArrayLike<unknown>