@typedly/array
Version:
A TypeScript type definitions package to handle array-related operations.
11 lines (10 loc) • 406 B
TypeScript
/**
* @description Converts an array to a union.
* @export
* @template {readonly Type[]} Array
* @template [Type=any]
* @example
* import { ToUnion } from '@typedly/array';
* type UnionFromArray = ToUnion<[1, 2, 3]>; // UnionFromArray will be: 1 | 2 | 3
*/
export type ToUnion<Array extends readonly Type[], Type = any> = Array extends [infer First, ...infer Rest] ? First | ToUnion<Rest> : never;