UNPKG

rambda

Version:

Lightweight faster alternative to Ramda

22 lines (19 loc) 574 B
import {IntersectOf} from './IntersectOf' /** Get the last item within an **union** * (⚠️ it might not preserve order) * @param U * @returns **any** * @example * ```ts * ``` */ export type Last<U extends any> = IntersectOf< U extends unknown // Distribute U ? (x: U) => void : never // To intersect > extends (x: infer P) => void ? P // Extract merged : never // ^^^ Last parameter // The above does this (i.e.) // ParamsOf<((a: 1) => void) & ((a: 2) => void)> // => [2]