import { ReyaTheme } from '.'; type ReyaThemeGetterParams = { theme: ReyaTheme; }; type ColorName = keyof ReyaTheme['colors']; export const getColor = (color: ColorName) => ({ theme }: ReyaThemeGetterParams): string => theme.colors[color]; type BooleanMatcher = { false: ColorName; true: ColorName }; type Matcher = { [key in T]: ColorName }; type MatcherType = Extract; export const matchColor = ( variable: K, matcher: U extends boolean ? BooleanMatcher : Matcher>, ) => (params: T) => { if (typeof params[variable] === 'boolean') { const booleanMatcher = matcher as BooleanMatcher; const color = params[variable] ? booleanMatcher.true : booleanMatcher.false; return getColor(color); } const color = (matcher as Matcher>)[ params[variable] as unknown as MatcherType ]; return getColor(color); };