Skip to main content

TupleToUnion

Use Object keys as a union type

API

const tuple = <T extends string[]>(...args: T) => args;
type TupleToUnion<T extends [...unknown[]]> = T[number];

Usage

import { tuple, TupleToUnion } from '@feedzai/js-utilities';

export const ICON_POSITION = {
left: 'left',
right: 'right',
} as const;

const IconPositionTuple = tuple(Object.keys(ICON_POSITION)); // ["left", "right"]

type IconPosition = TupleToUnion<typeof IconPositionTuple> // "left" | "right"