Skip to main content
Module

x/scaffold/src/deps/types.ts>LastArrayElement

scaffold your next project with style and 💗
Latest
type alias LastArrayElement
import { type LastArrayElement } from "https://deno.land/x/scaffold@0.3.0/src/deps/types.ts";

Extracts the type of the last element of an array.

Use-case: Defining the return type of functions that extract the last element of an array, for example lodash.last.

Examples

Example 1

import type {LastArrayElement} from 'type-fest';

declare function lastOf<V extends readonly any[]>(array: V): LastArrayElement<V>;

const array = ['foo', 2];

typeof lastOf(array);
//=> number

Type Parameters

ValueType extends readonly unknown[]
definition: ValueType extends readonly [infer ElementType] ? ElementType : ValueType extends readonly [infer _, ...infer Tail] ? LastArrayElement<Tail> : ValueType extends ReadonlyArray<infer ElementType> ? ElementType : never