/* eslint-disable @typescript-eslint/no-explicit-any */ import { Unpacked } from "types/utility-types"; type CustomEnum = Record & { is: (value: string) => boolean; _all: Array; } & Y; export function makeEnum< Values extends string, OtherProps extends Record, >( values: Array | Record, otherProps: OtherProps, ): CustomEnum, OtherProps> | CustomEnum { let enumObj: any; let set: any; if (Array.isArray(values)) { enumObj = {}; for (const value of values) { enumObj[value] = value; } set = new Set(values); enumObj._all = values; } else { enumObj = values; set = new Set(Object.values(values)); enumObj._all = Array.from(set); } enumObj.is = (value: string): boolean => { return set.has(value); }; if (otherProps) { for (const prop in otherProps) { enumObj[prop] = otherProps[prop]; } } return enumObj; }