ts-type-forge
    Preparing search index...

    Type Alias Head<T, D>

    Head: T extends readonly []
        ? D
        : T extends readonly [infer X, ...readonly unknown[]] ? X : T[number]

    Gets the type of the first element of a readonly tuple T. If the tuple is empty, it returns the default type D (defaults to never). For a general (non-tuple) array, it returns the element type.

    Type Parameters

    • T extends readonly unknown[]

      The readonly tuple type.

    • D = never

      The default type to return if T is empty. Defaults to never.

    The type of the first element, or D if T is empty.

    type H1 = Tuple.Head<[1, 2, 3]>; // 1
    type H2 = Tuple.Head<[]>; // never
    type H3 = Tuple.Head<[], 'default'>; // 'default'
    type H4 = Tuple.Head<readonly string[]>; // string