File tree Expand file tree Collapse file tree 2 files changed +13
-17
lines changed Expand file tree Collapse file tree 2 files changed +13
-17
lines changed Original file line number Diff line number Diff line change 11import * as CSS from 'csstype'
22import { themeGetter } from '../style'
3- import { ThemeNamespaceValue , ITheme , Theme } from '../types'
3+ import { SynthesizedPath , ITheme , Theme } from '../types'
44
5- export type ThemeColor < T extends ITheme = Theme > = ThemeNamespaceValue <
6- 'colors' ,
7- T
8- >
5+ export type ThemeColor < T extends ITheme = Theme > = SynthesizedPath < T [ 'colors' ] >
96export type Color < T extends ITheme = Theme > = ThemeColor < T > | CSS . Property . Color
107export const getColor = themeGetter < ThemeColor > ( {
118 name : 'color' ,
Original file line number Diff line number Diff line change @@ -115,18 +115,17 @@ export interface TransformValue {
115115 ) : CSSScalar
116116}
117117
118- // declare type SynthesizedPath<T> = {
119- // [P in keyof T]:
120- // | (T[P] extends { [key: string]: any; [key: number]: any }
121- // ? `${string & P}` | `${string & P}.${SynthesizedPath<T[P]>}`
122- // : `${string & P}`)
123- // | (number & P)
124- // }[T extends any[] ? number & keyof T : keyof T]
125-
126- // export type ThemeNamespaceValue<
127- // K extends string,
128- // T extends ITheme,
129- // > = SynthesizedPath<T[K]>
118+ /**
119+ * Recursively explores a given object and creates a union of the deep paths
120+ * leading to primitive values (non-objects.)
121+ */
122+ export type SynthesizedPath < T extends Record < string , unknown > > = {
123+ [ P in keyof T ] :
124+ | ( T [ P ] extends Record < string , unknown >
125+ ? `${string & P } .${SynthesizedPath < T [ P ] > } `
126+ : `${string & P } `)
127+ | number
128+ } [ T extends any [ ] ? number & keyof T : keyof T ]
130129
131130export type ThemeNamespaceValue < K extends string , T extends ITheme > =
132131 | NamespaceType < T [ K ] >
You can’t perform that action at this time.
0 commit comments